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]); | |
} | |
}; | |
}; |
Glad it was useful!
…On Mon, Aug 22, 2011 at 1:27 AM, arikfr < ***@***.***>wrote:
I wish I noticed your fork earlier... could've save me some time getting to
the same solutions... :-)
Thanks!
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1118201
Thanks for pointing out my syntax error - I fixed the original just in case anyone else runs across it.
hmm, where does one put this?
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
I wish I noticed your fork earlier... could've save me some time getting to the same solutions... :-)
Thanks!