Has anyone found a way to dynamically render partials?
I found this link for mustache.js but I am unsure how to implement this in php or if there is even away to do this in php. Even if it was the boolean flag method in the example in the link.
The basics of this would be to choose the partial based on the view file. Making the partial choosing dynamic and not have to specify it in the template.
I have tried using this exact method with only failures.
Content from Link:
View:
{
items: [
{ type: 'image', url: 'Some URL', is_image: true },
{ type: 'text', content: 'Some text', is_text: true }
]
}
Template:
base.mustache
{{#items}}
{{#is_text}}
{{>text}}
{{/is_text}}
{{#is_image}}
{{>image}}
{{/is_image?}}
{{/items}}
text.mustache
<p>{{content}}</p>
image.mustache
<p><img src="{{url}}"/></p>
...can be replaced with:
View:
{
items: [
{ partial: 'text', content: 'Some text' },
{ partial: 'image', url: 'Some URL' }
]
}
Template:
base.mustache
{{@items}}
text.mustache
<p>{{content}}</p>
image.mustache
<p><img src="{{url}}"/></p>