Skip to content

Instantly share code, notes, and snippets.

@tvpmb
Created June 22, 2012 15:55
Show Gist options
  • Select an option

  • Save tvpmb/2973659 to your computer and use it in GitHub Desktop.

Select an option

Save tvpmb/2973659 to your computer and use it in GitHub Desktop.
handlebars-jst-fetch
/*
fetch: function(path) {
path = path + ".html";
path = path.slice(1);
window.JST = window.JST || {};
if (JST[path]) {
return Handlebars.template(JST[path]);
}
var done = this.async();
$.get(path, function(contents) {
done(Handlebars.compile(contents));
});
},
*/
fetch: function(path) {
path = path + ".html";
path = path.slice(1);
if (!JST[path]) {
$.ajax({ url: path, async: false }).then(function(contents) {
//JST[path] = _.template(contents);
JST[path] = Handlebars.compile(contents);
});
}
return JST[path];
},
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