Is there any way to precompile Handlebars template, so that it will be aware about Ember.js helpers, like “action”, “view”, etc.?
The reason I’m asking is because I need to use Ember.js with a runtime-only build of the Handlebars (due to CSP in Google Chrome), and it seems that Ember.js does not completely support currently such scenario:
https://github.com/emberjs/ember.js/issues/1303
You can precompile an Ember Handlebars template using
Ember.Handlebars.precompile(ember-handlebars/lib/ext.js#L104).The basic strategy to use for precompilation outside of a browser (in node, for example) is:
template = Ember.Handlebars.precompile(string)Ember.TEMPLATES[name] = Ember.Handlebars.template(template)The
ember-railsgem for Rails does this for you if you have an asset with the extension.handlebars.The
ember-railsgem also maintains a shim.jsfile that you can use to precompile in other non-browser environments (ember-precompiler.js).