Skip to content


Subversion checkout URL

You can clone with
Download ZIP


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

rhettg opened this Issue · 1 comment

2 participants


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.


{{> rendervalues}}}



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:

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.


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

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.

@cjerdonek cjerdonek was assigned
@cjerdonek cjerdonek referenced this issue from a commit
@cjerdonek cjerdonek Merge branch 'issue_13' into development: closing issue #13.
Added test cases to check that View.template_path is respected.
@cjerdonek cjerdonek closed this
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.