JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.5.0-dev/mustache.min.js"></script>
<div class="main"><!-- content here --></div>
<script type="text/html" id="tpl">
{{#data}}
{{#names}}
Name: {{name}}
{{#nested}}{{name}}{{/nested}}<br>
{{/names}}
{{/data}}
</script>
<script type="text/html" id="tpl-nested">
— <b>{{name}}</b>
</script>
CSS
.main {
padding: 20px;
}
JavaScript
/* Nested templates in Mustache using lambda
* http://stackoverflow.com/questions/6846672/mustache-templating-nested-templates
*/
function renderNested(template_string, translate) {
return function() {
return function(text, render) {
return Mustache.to_html(template_string, translate(render(text)));
};
};
}
var template = $("#tpl").html();
var nested_template = $("#tpl-nested").html();
var model = {
data: {
names: [
{ name: "Foo" },
{ name: "Bar" }
],
nested: renderNested(nested_template, function(text) {
return { name: text };
})
}
};
var result = Mustache.to_html(template, model);
$(".main").html( result );