Embed Mustache Template Into Another Template
I am using Mustache for HTML templates and HoganJS as renderer. My problem is following: I have table template (table, header, body), but also I have template for each TR element o
Solution 1:
You're looking for Mustache's "partial" tag:
<script type="text/html" id="section_table_template">
<table>
<thead>
<tr><th>Name</th><th>Count</th></tr>
</thead>
<tbody>
{{# collection }}
{{> table_row }}
{{/ collection }}
</tbody>
</table>
</script>
To get this to work with Hogan, you simply have to tell it where your partials are:
<script>
var t = hogan.compile(document.getElementById('section_table_template').innerHTML);
var partials = {
table_row: document.getElementById('table_row_template').innerHTML
};
var rendered = t.render(context, partials);
</script>
Post a Comment for "Embed Mustache Template Into Another Template"