Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
91
rated 0 times [  96] [ 5]  / answers: 1 / hits: 15537  / 13 Years ago, mon, october 17, 2011, 12:00:00

I'm using handlebars.js on a project and I'm starting to have a fair amount of templates.
For now they are stored in my main template app file, like this :



<script id=avatar_tpl type=text/html>
bla bla bla {{var}} bla bla bla
</script>


I'm wondering if there is a way to put them in a separate file like a .js file or something, to avoid stacking them up in my source code page.



I'm aware that there are several solutions to call theses templates via Ajax, but that seems to result in too much unnecessary requests for me.



Thank you


More From » backbone.js

 Answers
15

I created and open-sourced NodeInterval for this exact same problem of too many js templates in my HTML page.



It allows you to put all your templates into a templates folder organized in whatever hierarchy you like. It has a built in watch capability so that as you modify any of these templates it automatically updates your HTML page. I use it alongside SASS for my CSS.



I use it daily with underscore templates but it should work fine with moustache templates as well:



https://github.com/krunkosaurus/NodeInterval


[#89575] Friday, October 14, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brittanye

Total Points: 263
Total Questions: 94
Total Answers: 115

Location: Burkina Faso
Member since Thu, Dec 23, 2021
2 Years ago
;