Self-referential Templates
Added *self
as a partial that refers to the whole template renderer.
var grandpaWorm = new DefineMap({
name: "Earthworm Jim",
child: {
name: "Grey Worm",
child: {
name: "MyDoom"
}
}
});
var renderer = stache(`
<span>{{name}}</span>
{{#./child}}
<div>
{{>*self}}
</div>
{{/child}}
`);
var view = renderer(grandpaWorm);
The view variable will be a document fragment:
<span>Earthworm Jim</span>
<div>
<span>Grey Worm</span>
<div>
<span>MyDoom</span>
</div>
</div>