Jammit Handlebar Template funciton
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
Handlebars.template = function(templateString) { | |
return function () { | |
if (arguments.length < 1) { | |
// With no arguments, return the raw template -- useful for rendering | |
// partials. | |
return templateString; | |
} else { | |
Handlebars.templates = Handlebars.templates || {} | |
Handlebars.templates[templateString] = Handlebars.templates[templateString] || Handlebars.compile(templateString); | |
return Handlebars.templates[templateString](arguments[0], arguments[1]); | |
} | |
}; | |
}; |
You can put it anyplace after the handlebars script tags and before you actually need a template.
what version of handlebars are you running this against?
this actually seems to do the trick with the latest version of handlebars: template_function: Handlebars.compile
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hmm, where does one put this?