Last active
October 31, 2022 05:44
-
-
Save jeremychone/8249779 to your computer and use it in GitHub Desktop.
Simple HTML and js templates
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
// Just a little indirection to render a template using handlebars. | |
// This simple indirection allows much flexibility later one, | |
// when using pre-compiling or other templating engine are needed. | |
Handlebars.templates = Handlebars.templates || {}; | |
function render(templateName,data){ | |
var tmpl = Handlebars.templates[templateName]; | |
if (!tmpl){ | |
tmpl = Handlebars.compile($("#" + templateName).html()); | |
Handlebars.templates[templateName] = tmpl; | |
} | |
return tmpl(data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment