I am trying to figure out how to store jQuery templates in different files from the base html (without using a string or ajax request).
For example, in my html page, I would like to do this:
<script type ="text/x-jquery-tmpl" id="personTmpl" src="js/personApp.tmpl.html"></script> <div id="container"></div> <script type="text/javascript"> var p = { name: 'joe' }; $( "#personTmpl" ).tmpl( p ).appendTo( "#container" ); </script>
If #personTmpl is defined in personApp.tmpl.html (or somewhere else)
The ultimate goal is to just keep my template separate from js code (and html).
I don't like the string method because it makes editing tough for longer templates. And I donβt want to run an ajax request to load (note that the template file will eventually be aggregated for production).
Thoughts?
source share