New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic Partials #241
Comments
Thinking about this a little more, how about we allow the {
items: [
{ type: 'image', title: 'Some title', partial: 'image.mustache' },
{ type: 'text', content: 'Some text', partial: 'text.mustache' }
]
} ...could be rendered using: {{>items}} And if you wanted more control i.e. wrap each partial, we could have: {{#items}}
<p>Before</p>
{{>.}}
<p>After</p>
{{/items}} ...or, alternate syntax (can't decide): {{#items}}
<p>Before</p>
{{@partial}}
<p>After</p>
{{/items}} What do people think? This is a common pattern that comes up and that needs addressing. Jamie |
Mustache deals with the dynamic scenario using Higher Order Sections. Basically, you can do the following:
This will output:
It is a little clunky and the behaviour of higher order sections is not so well defined in the specification, but it works if you understand the limitations and what exactly the /this/ variable is pointing to. Hope that helps. |
That's exactly why I think we need a proper solution to this common scenario as that workaround is ugly as hell. |
Please see Pull Request: #242 |
Update: please see pull request for new solution: #242.
Hi,
I might be missing something obvious but can't think of a way to dynamically render a partial based on a value. For example, given the view below:
I want to dynamically render a partial based on the 'type' key:
This obviously won't work but I thing there needs to be some way of doing this. Not sure what the syntax would be, something like the following(?):
or even...
{{>items:type}}
Currently, the only way to achieve this that I can see is to do the following:
Someone else has come up against the same problem here: http://stackoverflow.com/questions/2932679/dynamically-render-partial-templates-using-mustache
Kind regards,
Jamie
The text was updated successfully, but these errors were encountered: