Skip to content

Instantly share code, notes, and snippets.

@borismus
Created March 23, 2012 00:06
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save borismus/2165681 to your computer and use it in GitHub Desktop.
Save borismus/2165681 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();
}
});
}
@teabyii
Copy link

teabyii commented Apr 4, 2014

Very good! I take it!

however, there is a little problem:
in 9 lines, miss ; in the end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment