Skip to content
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

Kohana_Layout renders the content partial twice #55

Open
dolfelt opened this issue Dec 18, 2012 · 9 comments
Open

Kohana_Layout renders the content partial twice #55

dolfelt opened this issue Dec 18, 2012 · 9 comments

Comments

@dolfelt
Copy link

dolfelt commented Dec 18, 2012

I was having difficulty getting some lambda functions working until I realized that the $m->setPartials() function takes unrendered content. The current code in Kohana_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 the Kohana_Layout and changing the render function.

@zombor
Copy link
Owner

zombor commented Dec 18, 2012

I'm really lost about what the problem is here. :)

@dolfelt
Copy link
Author

dolfelt commented Dec 19, 2012

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.

@dolfelt
Copy link
Author

dolfelt commented Dec 19, 2012

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.

@vukers
Copy link

vukers commented Jan 15, 2013

@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.

@zombor
Copy link
Owner

zombor commented Jan 16, 2013

Sounds like a bug in the mustache renderer? I know this used to work in mustache v1.

@zsoerenm
Copy link

Yes, Kostache_Layout::CONTENT_PARTIAL => parent::render($class, $template) is not needed as partials get rendered anyway.
file_get_contents would do the job!

@evanpurkhiser
Copy link
Contributor

@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.

@zombor
Copy link
Owner

zombor commented Mar 15, 2013

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 :)

@polarina
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants