I need to store HTML templates to use them for Mustache rendering.
<!-- Templates. -->
<span style="display:none">
<span id="tplCard">
{{#.}}
<div class="card">
<div class="caption">
<p>{{caption}}</p>
<button title="Edit" class="toolbar edit"></button>
</div>
</div>
{{/.}}
</span>
<span id="tplRow">
{{#.}}
<tr>
<td>{{id}}</td>
<td>{{caption}}</td>
<td>{{text}}</td>
<td>{{image}}</td>
<td>
<button>Edit</button>
</td>
</tr>
{{/.}}
</span>
</span>
<!-- End of templates. -->
Here is the using:
function FillWithData(container, template, data)
{
var tpl = $('#' + template).html();
var html = Mustache.render(tpl, data);
$('#' + container).append(html);
}
The first template works, but the second one doesn't. Well, the problem is a <TR>
is not a valid child for a <SPAN>
, so the browser gets rid of them. How to store a random template?