1

I have a fairly big webapp with lot of templates. I am looking to save time by precompilation of these files.

Currently, I use a script wrapper so that I can load it dynamically and package them in html

<script id="all-domain-users-model-template" type="text/html">
<td></td>
<td>{{domain}}</td>
<td>{{name}}</td>
<td>{{email}}</td>
<td>{{is_account_owner}}</td>
<td>{{#if is_account_owner}}<a href="#" data="{{domain}}" class="delete-namespace btn btn-danger">Delete</a>{{/if}}</td>
</script>

There are many many such files. One file can have more than one definition..

I am looking for ideas for a script to read the name in id, parse html, compile and put it back using id.templates in a js file.

I have seen Using pre-compiled templates with Handlebars.js (jQuery Mobile environment) - the accepted answers mentions that the script tag was removed before copying.. But in reality, its almost impossible..

Community
  • 1
  • 1
cloudpre
  • 915
  • 1
  • 14
  • 25

1 Answers1

0

I use grunt-ember-templates to precommpile my ember handlebars templates.

For a good example of this grunt plugin in use check out this example todos application.

It gives a good example of using grunt for your build process, testing, etc, and includes template precompilation.

CraigTeegarden
  • 8,013
  • 8
  • 35
  • 43
  • Precompiling is not an issue. Does grunt parse the templates in script tag and automatically output with the name in the id? – cloudpre May 17 '13 at 03:41
  • @cloudpre Why would you need the script tag around a precompiled template? The advantage or precompiling is, that all your templates got stuffed into the `Ember.TEMPLATES` template cache and Ember is able to call the templates itself automatically. If you take each of your templates, pack it in it's own `.handlebars` file and use `Grunt` for precompilation it is possible to later address your templates by the previously given file name (e.g. 'my-fine-template'). – herom May 17 '13 at 04:19
  • @herom We have already built our app with lot of templates. Each template has type="text/x-handlebars-template". We need a way where I can read these files which already have script tag and precompile them automatically. Script for precompiled is not required. Given that there are many templates, we only load few things by default and others are loaded dynamically and then added to the list. – cloudpre May 17 '13 at 04:34
  • @cloudpre I see, thanks for clearing things out. Are all your `Handlebars` scripts on your main page or are they organized in separate files? – herom May 17 '13 at 05:37
  • I'm still not exactly sure what the issue is... would something like this help? http://stackoverflow.com/questions/9469235/is-it-possible-to-load-a-handlebars-template-via-ajax – CraigTeegarden May 17 '13 at 13:47