I'm playing with it right now in Python (note that I'm the creator of Mako), adding a dynamic context that grabs sections seems to be doing the right thing, although I will need to check this out a lot more.
We mainly use lambdas, where the "<" prefix indicates "inherit from this template" (similar to the syntax discussed at https://github.com/mustache/spec/issues/38 ), and the prefix "$" indicates "this is inherited section".
import pystache class NameSpace(object): def __init__(self, renderer, vars_={}): self.renderer = renderer self._content = {} self.vars = vars_ def add_content(self, name, value): self._content[name] = value def __getattr__(self, key): if key in self.vars:
So, here are some templates. base.mustache:
<html> {{#$header}} default header {{/$header}} {{#$body}} default body {{/$body}} {{#$footer}} default footer, using {{local key}} {{/$footer}} </html>
hello.mustache:
{{#<base}} {{#$header}} new header {{/$header}} {{#$body}} new body, with {{local key}} {{/$body}} {{/<base}}
and then play with three levels of depth, subhello.mustache:
{{
Rendering hello.mustache as follows:
renderer = pystache.Renderer(search_dirs=["./templates/"]) print renderer.render_name("hello", NameSpace(renderer, {"local key": "some local key"}))
exit:
<html> new header new body, with some local key default footer, using some local key </html>
subhello.mustache rendering:
print renderer.render_name("subhello", NameSpace(renderer, {"local key": "some local key"}))
exit:
<html> new header new body, with some local key im some new footer </html>
I just wrote this in twenty minutes, and I only used handlebars.js a little in the past and pystache for the first time, so the whole idea of ββa "mustache" is not for me. But does it work?