Skip to content
This repository

Template path not propagated when rendering a partial inside a section #13

Closed
rhettg opened this Issue September 27, 2010 · 1 comment

2 participants

Rhett Garber Chris Jerdonek
Rhett Garber

Related to issue #8, if you put a partial within a section, it won't be able to find the template if you are using 'template_path' in your view.

outer.mustache

{{#somevalues}}
{{> rendervalues}}}
{{/somevalues

rendervalues.mustache:

{{name}}

If you set template_path in your view for outer.mustache, that template_path is not used to find rendervalues.mustache because though we are using a View, the values aren't 'inherited'.

Bug is in here:

@modifier('>')
def render_partial(self, tag_name=None, context=None):
    """Renders a partial within the current context."""
    # Import view here to avoid import loop
    from pystache.view import View

    view = View(context=context)
    view.template_name = tag_name

    return view.render()

In the above, the view 'settings' would be correctly copied over if context was a view, but since this is while rendering a section, context is something else.

The real issue is the strange relationship between templates and views. As the comment above indicates, there is a 'loop' between views and templates... Really it's a bad case of tight coupling. Views need templates, and templates need views.

Chris Jerdonek
Collaborator

I believe the specific issue raised by this post has been addressed in master by now, as well as in the development branch:

@modifiers.set('>')
def _render_partial(self, template_name):
    markup = self.view.load_template(template_name)
    template = Template(markup, self.view)
    return template.render()

And in the View class:

def load_template(self, template_name):
    from pystache import Loader
    return Loader().load_template(template_name, self.template_path,
                                  encoding=self.template_encoding, extension=self.template_extension)

However, we should still add a test case to check that "template_path" is being honored (or verify that we already have such a test case).

I also agree that templates and views should not depend on each other. It looks like the code may have tied them even further together since this issue was initially filed.

Chris Jerdonek cjerdonek referenced this issue from a commit December 10, 2011
Chris Jerdonek Merge branch 'issue_13' into development: closing issue #13.
Added test cases to check that View.template_path is respected.
623957a
Chris Jerdonek cjerdonek closed this December 11, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.