Open dolfelt opened 11 years ago
I'm really lost about what the problem is here. :)
If you change your delimiter using {{=<% %>=}}
so you can use {{ }}
for your JS templates, it won't work within the content partial because the content is rendered twice. First time changes the delimiter and keeps the curly braces, and the second time removes those braces.
Place the following inside a content template (not the layout template):
{{=<% %>=}}
{{should_show}}
{{#also_show}}
{{var}}
{{/also_show}}
The previous code example should render the mustache tags into the HTML sent to the browser, but that is not what is happening.
@dolfelt, I was facing a similar issue: I had a variable $foo
:
public $foo = 'These {{brackets}} should appear.';
which I wanted to place in a page which used Kostache_Layout. Stepping through the code showed that it would render twice, causing the {{brackets}}
portion to be stripped out.
I came to the solution of using:
{{=<% %>=}}{{ foo }}<%={{ }}=%>
which properly rendered the brackets.
I think the same solution can address your issue if you were to put your code section:
{{should_show}}
{{#also_show}}
{{var}}
{{/also_show}}
within a variable, possibly even a partial.
Sounds like a bug in the mustache renderer? I know this used to work in mustache v1.
Yes, Kostache_Layout::CONTENT_PARTIAL => parent::render($class, $template) is not needed as partials get rendered anyway. file_get_contents would do the job!
@zsoerenm is right.
The Kostache_Layout::render()
method actually renders two things. First the actual content of the page is rendered and then set as the content
partial for the layout template. Then the layout is rendered. Since the content partial was already rendered and injected as a partial this opens up potential bugs like the one describe above.
The content partial should be set to the source mustache file, NOT the rendered mustache file.
We only have a filesystem partial loader. I'm busy for the next week, so if there's a patch you have, let's see it :)
Could the patch be applied anytime soon? I stumbled upon this bug too, shot me in the foot. I manually applied the patch provided by EvanPurkhiser and it works fine now. Thanks.
I was having difficulty getting some lambda functions working until I realized that the
$m->setPartials()
function takes unrendered content. The current code inKohana_Layout
renders the partial before it is set, then Mustache renders it again. Normally this wouldn't be a big deal, but if you attempt to change the delimiter, it matters. I ended up extending theKohana_Layout
and changing the render function.