Skip to content

Self-referential Templates

Compare
Choose a tag to compare
@Sinjhin Sinjhin released this 07 Sep 18:34
· 776 commits to master since this release

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>