Would it be possible to pass a sub-tree as parameter to a partial?
See original GitHub issueApologies if this has been previously discussed or is simply unpractical to implement, but I wish there as a way to pass a sub-tree of DOM elements to a partial as a parameter.
Example:
<!-- Calling the partial -->
{>"components/my-component1" parameter1="foobar"}
<div class="component__inner">
<p>Hello world</p>
</div>
{<}
<!-- Inside the partial -->
<div class="component component--{parameter1}">
{_content}
</div>
Result:
<div class="component component--foobar">
<div class="component__inner">
<p>Hello world</p>
</div>
</div>
This would allow developers to create self-contained and reusable components as Dust.js partials. You can argue that this is technically possible now, but one would have to pass any markup required by the component as a normal parameter, which can get messy very easily:
{>"components/my-component1" parameter1="foobar" content="<div class='component__inner'><p>Hello world</p></div>"}
A similar approached is used by Sass in their mixins, as developers can define normal parameters as well a special code block defined as @content
.
@mixin component1($arg1, $arg) {
.component1 {
width: $arg1;
height: $arg2;
@content;
}
}
React components also make this possible through this.props.children
.
I’d love to hear your thoughts about this. Thanks in advance!
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
asp.net mvc3: How to pass parameters from controller to a ...
1 Answer 1 ... I think you could use @Html.RenderAction instead of RenderPage. Then you can design an action, pass parameters and choose...
Read more >passing parameters to a partial - Using Umbraco And Getting ...
I want to be able to use the same partial multiple times in a template, but pass it the value of different aliases...
Read more >8 Scapegoat Trees - Open Data Structures
A ScapegoatTree keeps itself balanced by partial rebuilding operations. During a partial rebuilding operation, an entire subtree is deconstructed and rebuilt ...
Read more >A program to check if a Binary Tree is BST or not
If the value of the right child of the node is less than or equal to the current node then return false; If...
Read more >11.8.2 - Minimal Cost-Complexity Pruning - STAT ONLINE
The complexity parameter α adjusts that. ... If the optimal subtrees are nested, the computation will be a lot easier. ... Here we...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone interested, this is possible by creating a very simple helper used to call a partial and inject its content block as a parameter:
A more detailed explanation can be found here.
That’d be great. Thank you!