Skip to content

Instantly share code, notes, and snippets.

@joshrhoades
Last active December 18, 2015 17:28
Show Gist options
  • Save joshrhoades/5818274 to your computer and use it in GitHub Desktop.
Save joshrhoades/5818274 to your computer and use it in GitHub Desktop.
Function to expose precompiled handlebars as part of the handlebars object to make it easier to use HB in both DEV (runtime compile) and PROD (build/release-time compile)
Handlebars.getTemplate = function(name) {
if (Handlebars.templates === undefined || Handlebars.templates[name] === undefined) {
$.ajax({
url : 'templatesfolder/' + name + '.handlebars',
success : function(data) {
if (Handlebars.templates === undefined) {
Handlebars.templates = {};
}
Handlebars.templates[name] = Handlebars.compile(data);
},
async : false
});
}
return Handlebars.templates[name];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment