Skip to content

Instantly share code, notes, and snippets.

@tvpmb
Created March 2, 2012 04:47
Show Gist options
  • Save tvpmb/1955761 to your computer and use it in GitHub Desktop.
Save tvpmb/1955761 to your computer and use it in GitHub Desktop.
fetch templates for bb layoutmanager
Backbone.LayoutManager.configure({
paths: {
layout: "//app/layouts/",
template: "//app/templates/"
},
fetch: function(path) {
path = path + ".html";
path = path.slice(1);
window.JST = window.JST || {};
// Should be an instant synchronous way of getting the template, if it
// exists in the JST object.
if (JST[path]) {
return Handlebars.template(JST[path]);
}
var done = this.async();
/* $.ajax({
url: path,
cache: true,
success: function(contents) {
done(Handlebars.compile(contents));
}
}); */
$.get(path, function(contents) {
done(Handlebars.compile(contents));
});
},
render: function(template, context) {
return template(context);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment