问题
How do you use partial layouts in pystache? I haven't been able to find any documentation for doing this. I'm looking for something along the lines of
layout.html
<html>
<body>
{{<body}}
</body>
</html>
index.html
<section>
{{name}}
</section>
Edit:
I've done this using node.js and am familiar with the templating syntax, but I'm not sure how to tell pystache to load both files.
回答1:
Pystache is just a Python implementation of Mustache, so the Mustache documentation should apply to Pystache as well. Check out the Partials section of the man page.
layout.mustache
<html>
<body>
{{> body}}
</body>
</html>
body.mustache
<section>
{{name}}
</section>
Here's an example of rendering the above templates in Pystache (from the same directory as the .mustache
files):
>>> import pystache
>>> renderer = pystache.Renderer()
>>> renderer.render_path('layout.mustache', {'name': 'test'})
u'<html>\r\n <body>\r\n <section>\r\n test\r\n ...'
For more info, check out the Pystache source.
来源:https://stackoverflow.com/questions/13918028/rendering-multiple-files-with-pystache