*self
Used to reference the current template and recursively render it
Deprecated 4.0
{{>*self}}
is deprecated in favor of {{>scope.view}}
{{>*self}}
The entirety of the current template is always stored as a named partial *self
<div>
{{>*self}}
</div>
Use
This can be used to recursively render a template given a stop condition. Note that we use a key expression to set local scope. Also note it is a dot slash on the child key expression. The dot slash prevents walking up the scope. See Too Much Recursion for more details.
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 the document fragment:
<span>Earthworm Jim</span>
<div>
<span>Grey Worm</span>
<div>
<span>MyDoom</span>
</div>
</div>
A template variable can be passed in
var grandpaWorm = new DefineMap({
child: {
name: "Earthworm Jim",
hasArms: false,
child: {
name: "Grey Worm",
child: {
name: "MyDoom"
}
}
}
});
var renderer = stache(`
<p>{{name}}</p>
<p>{{hasArms}}</p>
{{#./child}}
<div>
{{>*self}}
</div>
{{/child}}
`);
var view = renderer(grandpaWorm);
The view variable will be the document fragment:
<p>Earthworm Jim</p>
<p>false</p>
<div>
<p>Grey Worm</p>
<p>false</p>
<div>
<p>MyDoom</p>
<p>false</p>
</div>
</div>
For a more detailed explanation of using partials recursively, see Too Much Recursion.