<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0-alpha.2/handlebars.min.js"></script>
var rawTemplate = $('#itemTemplate').html();
var compiledTemplate = Handlebars.compile(rawTemplate);
var finishedHtml = compiledTemplate(obj);
$('#items').append(finishedHtml);
<script id="itemTemplate" type="text/x-handlebars-template">
<div class="header">{{title}}</div>
<div class="body">
<div>{{type}}</div>
<div>{{price}}</div>
</div>
</script>
var product = {
title : "Cheese",
type : "Sharp Cheddar",
price : "$3.49"
}
{{#if type}}
<div>Type: {{type}}</div>
{{else}}
<div>Type: None</div>
{{/if}}
{{#each products}}
<div>{{title}}</div>
<div>{{price}}</div>
{{/each}}
Handlebars.registerHelper('formatMoney', function(arg1) {
return Handlebars.SafeString('$' + arg1);
});
{{formatMoney price}}
//price is a property from your object
//constructor declaration
function CustomObject() {};
//using constructor to create an object
var myObj = new CustomObject();
myObj instanceof CustomObject;
// > true