A demo to show how handlebars precompilation works
- keep all the template files with
.handlebars
extension inside thetemplates folder
. - In the root folder run
handlebars templates/ -f templatesCompiled.js
- You will get a compiled
templatesCompiled.js
in the root directory. - Insert the runtime handlebars and the compiled js file
<script src="handlebars.runtime.js"></script>
<script src="path/to/templatesCompiled.js"></script>
- Access the template of
demo.handlebars
by using
var context = {
"name":"Ritesh Kumar",
"occupation" : "Developer"
}
var templateScript = Handlebars.templates.demo(context);
$(body).append(templateScript);
- Run
index.html
on the browser to see the resultant html.
That's it.