I am using jsrender as the JavasScript template engine. The usage is quite straightforward:
In HTML Page, define a script tag with template-ed HTML content:
<script id="myTemplate" type="text/x-jsrender">
<div>{{:name}} ({{:year}})</div>
</script>
...
<body>
<div id="content"></div>
</body>
In JavaScript, define a variable, and call render function against the template:
var model = {
name: "Findekano",
year: 2012
};
$('#content').html($('#myTemplate').render(model));
The question is:
I do not want to keep the template definition in the host HTML page, I'd like to keep it in a separate file along with the JavaScript file so it can be more modular.
I'd like to have something to work as below:
<script id="myTemplate"
type="text/x-jsrender"
src="template/myTemplate.html">
</script>
where myTemplate.html defines the necessary HTML template snippet. I tried the code above but it doesn't work. Could anyone suggest an alternative way to solve the problem?