/handlebars-precompilation-demo

A demo to show how handlebars precompilation works

Primary LanguageJavaScript

handlebars-precompilation-demo

A demo to show how handlebars precompilation works

  1. keep all the template files with .handlebars extension inside the templates folder.
  2. In the root folder run handlebars templates/ -f templatesCompiled.js
  3. You will get a compiled templatesCompiled.js in the root directory.
  4. Insert the runtime handlebars and the compiled js file
<script src="handlebars.runtime.js"></script>
<script src="path/to/templatesCompiled.js"></script>
  1. Access the template of demo.handlebars by using
var context = {
	"name":"Ritesh Kumar",
	"occupation" : "Developer"
}

var templateScript = Handlebars.templates.demo(context);

$(body).append(templateScript);
  1. Run index.html on the browser to see the resultant html.

That's it.