Last active
December 18, 2015 17:28
-
-
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)
This file contains hidden or 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
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