1
votes

I'm using precompiled templates for several reasons:

  1. Performance (no need to re-compile at runtime)
  2. Code separation (cleaner than embedding <script> tags and hardcoding in JS)
  3. 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):

  1. Precompile Ember-friendly templates (how can I do this via a command line?)
  2. 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

1

1 Answers

2
votes

Yes, the plain Handlebars compiler compiles to different JavaScript than Ember.Handlebars, so you cannot consume its output with Ember.

I don't know of a way to run Ember.Handlebars through the command line, though it should be possible in principle to write something.

To find out how to precompile with Ember.Handlebars, take a look at the source code of ember-rails - it supports precompilation.