Skip to content

Instantly share code, notes, and snippets.

@scruffyfox
Created April 20, 2016 08:03
Show Gist options
  • Save scruffyfox/2dce2b931d21386e6ce7de859bcd892d to your computer and use it in GitHub Desktop.
Save scruffyfox/2dce2b931d21386e6ce7de859bcd892d to your computer and use it in GitHub Desktop.
Load handlebars template
// usage: var itemTemplate = Handlebars.getTemplate("templatename");
Handlebars.getTemplate = function(name)
{
if (Handlebars.templates === undefined || Handlebars.templates[name] === undefined)
{
$.ajax({
url : 'templates/' + name + '.hbs',
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