As is in any project expected, 90% of my main HTML file is composed of many different templates, just like this:
<script type="text/template" id="template-parametros">
<div id="parametros">
<h2>Parâmetros</h2>
<table id="tab-parametros">
<tr><td>Descrição</td><td>Tipo</td><td>Locale</td></tr>
</table>
<button id="parametros-ad">Adicionar</button>
</div>
</script>
I'd like to put them elsewhere, so the UX guys can work on them on their own. Putting them in another file is easy, but how can I import them later? I've tried but then the browser tries, and, of course, fails, to interpret it as javascript code. type="text" also fails. Any idea?
Thank you!
how about:
I use a module loader (requireJS) which has a text plugin. It allows you to define your template file as an argument and use inside the Backbone View.
A Backbone View with require looks something like this.
To add to this, using underscore's
_.template()
it's easy to interpolate values.Say my templateFileName.html looks like this
All you have to do is pass in the hash with those property names to populate the html.