Skip to content

Instantly share code, notes, and snippets.

@zoghal
Forked from borismus/gist:2165681
Created May 24, 2012 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoghal/2783361 to your computer and use it in GitHub Desktop.
Save zoghal/2783361 to your computer and use it in GitHub Desktop.
dynamic template loading
/*
* Loads a handlebars.js template at a given URL. Takes an optional name, in which case,
* the template is added and is reference-able via templateName.
*/
function loadTemplate(url, name, callback) {
var contents = $.get(url, function(templateText) {
var compiledTemplate = Ember.Handlebars.compile(templateText);
if (name) {
Ember.TEMPLATES[name] = compiledTemplate
} else {
Ember.View.create({ template: compiledTemplate }).append();
}
if (callback) {
callback();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment