I'm relatively new to this, so please excuse if I'm missing some obvious point...
I'd like to create a reusable widget using Handlebars, for simplicity let's consider a Users table:
<script type="text/x-handlebars-template" id="temp1">
<table>
{{#users}}
<tr><td>{{name}}</td><td>{{email}}</td></tr>
{{/users}}
</table>
</script>
<script>
var template=Handlebars.compile($("#temp1").html());
function renderUsersTable(users, divId){
$("#"+divId).html(template(users:users));
}
<script>
This works, but I only got it to work with the template script (text/x-handlebars-template) embedded into my business page. That's not reusable: if I need it on another page, I'll need to copy-paste. I considered quoting the template into a javascript string variable, but that's ugly especially since my real html is pretty large.
Are there any better practices, that allow to separate the handlebars template into a dedicated file, to be included into different pages as needed?
Thanks very much