Created
April 20, 2016 08:03
-
-
Save scruffyfox/2dce2b931d21386e6ce7de859bcd892d to your computer and use it in GitHub Desktop.
Load handlebars template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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