Skip to content

Instantly share code, notes, and snippets.

@kwokhou
Created June 26, 2013 23:11
Show Gist options
  • Save kwokhou/5872586 to your computer and use it in GitHub Desktop.
Save kwokhou/5872586 to your computer and use it in GitHub Desktop.
Load external template for EmberJS
// Getting a external handlebar template via jQuery.get()
// and compile template and register it to Ember
function loadTemplate(url, name, callback) {
var contents = $.get(url, function(data) {
var compiled = Ember.Handlebars.compile(data);
if (name) {
Ember.TEMPLATES[name] = compiled
}
else {
Ember.View.create({ template: compiled }).append();
}
if (callback) {
callback();
}
})
.fail(function() { console.log("error getting external template"); })
.always(function() { console.log("finished register external template"); });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment