I'm using precompiled templates for several reasons:
- Performance (no need to re-compile at runtime)
- Code separation (cleaner than embedding
<script>
tags and hardcoding in JS) - Content security policy (this is for an extension).
Basically, I'm generating templates.js
via the handlebars command line utility, based on several template.handlebars
files. Next I try to bring these templates into Ember with the following loop:
for (var name in Handlebars.templates) {
var template = Handlebars.templates[name];
Ember.TEMPLATES[name] = template;
}
The result is weird: text seems to be loaded, but many template features (eg. {{outlet}}
) don't work. I suspect that this is because Handlebars and Ember-Handlebars are not the same thing.
I guess there are two options (and questions):
- Precompile Ember-friendly templates (how can I do this via a command line?)
- Properly import Handlebars templates into Ember (how?)
UPDATE: As per the answer, Ember.Handlebars is not the same as Handlebars, so the precompilation is different. Wrote a simple script to precompile for Ember: https://gist.github.com/3723927