Skip to content

Instantly share code, notes, and snippets.

@tomasdev
Created March 6, 2013 05:51
Show Gist options
  • Save tomasdev/5097042 to your computer and use it in GitHub Desktop.
Save tomasdev/5097042 to your computer and use it in GitHub Desktop.
Ember Handlebars external templates
// Taken from http://stackoverflow.com/questions/10274391/is-it-possible-to-load-handlebar-template-with-script-tag-or-define-handlebar-t/13474886#13474886
Ember.View.reopen({
templateForName: function(name, type) {
if (!name) { return; }
var templates = Ember.get(this, 'templates'),
template = Ember.get(templates, name);
if (!template) {
$.ajax({
url: 'scripts/templates/%@.handlebars'.fmt(name),
async: false
}).success(function(data) {
template = Ember.Handlebars.compile(data);
});
}
if (!template) {
throw new Ember.Error('%@ - Unable to find %@ "%@".'.fmt(this, type, name));
}
return template;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment