The template parser turns the template into Javascript code that is executed.
Templates can be unobtrusively stored inside of the HTML document like this:
<script type="text/html" id="script"> <div> <b><#= content #><b> <# for(var i=0; i < names.length; i++) { #> Name: <#= names[i] #> <hr /> <# } #> </div> </script>
And can then be called like this:
var tmpl = $("#itemtempalte").html(); // grab the template content var data = { content: "This is some textual content", names: ["rick","markus"] }; //assign the content with jQuery $("#divOutput").html( parseTemplate(tmpl,data) );
parseTemplate(templateString,data)
data
The data item that is applied to the template. You can only pass a single item in but you can use a root object that has hierarchical children.