Created
March 6, 2013 05:51
-
-
Save tomasdev/5097042 to your computer and use it in GitHub Desktop.
Ember Handlebars external templates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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