Recently I’ve been exploring Backbone, and they do encourage using a template engine.
Now, I’ve got a bunch of html files that I want to display using that, and I will most likely have to edit them often in the development stage. The most tutorials I read recomment something like this:
<script type="text/template" id="template1">
<ul>
<li>Hic sunt dracones</li>
</ul>
</script>
<script type="text/javascript">
template = $('#template1').html();
<script>
So I’d like to know if this can be made to work with the src-attribute to include the template files. Or, if not, what is the usual approach to load template files?
Using
srcfor this is not possible.You could include a JavaScript file though which is generated on the server from separate template files; with PHP it could be as simple as this:
Loading this file with a
<script>tag then gives you an objecttemplateswhere you can acccess the various templates viatemplates.foo,templates.bar, etc.