Reputation: 14674
I have a Mustache template which includes some partials. I want to load the partial into a string in PHP, with the contents of the partials included in the string. But I don't want the template to be parsed.
eg, if I have this Mustache template, myTemplate.mustache
:
{{> partials/myPartial }}
{{ my_text }}
and this is partials/myPartial.mustache
:
{{ my_header }}
then I want to load myTemplate.mustache
and have a PHP variable containing:
{{ my_header }}
{{ my_text }}
I can see how to get the contents of the template using new Mustache_Loader_Filesystem()->load()
but that doesn't include the contents of the partial.
Upvotes: 0
Views: 275
Reputation: 5117
You can't see a way to do that, because it's not possible. Mustache itself never even deals with templates merged together like that, so there's no reason it would expose an API for getting them.
Because of the nature of partials, it's not as simple as replacing a partial tag with the contents of that template. For example, partials don't inherit delimiter changes and pragmas from templates which include them, so that would have to be addressed. Partials are also indented to the level of the tag which includes them, so replacing a partial tag with the contents of the partial would have to do this as well.
I supposed if you really want it, you could load the template and partials, then use the Mustache Tokenizer to find partials tags in the template source then replace them (recursively) with the contents of the associated partials. Then you'd have to figure out how to change delimiters at the start and end of the inlined partials (or disallow delimiter changes entirely, which you could do by throwing an exception if you encounter one while processing the parsed template). And I can't think of a way to remove pragmas once they're added, so you would either have to disallow pragmas, or ensure that all inlined partials were compatible with whatever pragmas were being used in parent templates.
It'd be a fair amount of work, to say the least.
Upvotes: 1