I am working on a Backbone.js application. We use underscore.js templates to load content into a view. Currently, we have all the templates inside the index.html file, so the file size is increasing. Can someone help me find a solution to split these patterns into other files? Thanks in advance.
EDIT
I recently visited Backbone patterns , and I found that we can use JST to create separate template files for each template. They explained that we can create a jst.js file to fit all of our boilerplate code:
// http://myapp.com/javascripts/jst.js window.JST = {}; window.JST['person/contact'] = _.template( "<div class='contact'><%= name %> ..." ); window.JST['person/edit'] = _.template( "<form method='post'><input type..." ); <script src="http://myapp.com/javascripts/jst.js"></script>
Now all the templates are in the jst.js file. But if you have many templates, and you want to move the templates to separate files, you can create separate template files:
// http://myapp.com/javascripts/jst.js window.JST = {}; //http://myapp.com/javascripts/contactPerson.template.js window.JST['person/contact'] = _.template( "<div class='contact'><%= name %> ..." ); //http://myapp.com/javascripts/editPerson.template.js window.JST['person/edit'] = _.template( "<form method='post'><input type..." ); <script src="http://myapp.com/javascripts/jst.js"></script> <script src="http://myapp.com/javascripts/contactPerson.js"></script> <script src="http://myapp.com/javascripts/editPerson.js"></script>
Please let me know if there is a simpler idea. Thanks!
abhidsm
source share