Skip to content

Instantly share code, notes, and snippets.

@jeremychone
Last active October 31, 2022 05:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremychone/8249779 to your computer and use it in GitHub Desktop.
Save jeremychone/8249779 to your computer and use it in GitHub Desktop.
Simple HTML and js templates
// 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