How to get index in Handlebars each helper?

In the newer versions of Handlebars index (or key in the case of object iteration) is provided by default with the standard each helper. snippet from : https://github.com/wycats/handlebars.js/issues/250#issuecomment-9514811 The index of the current array item has been available for some time now via @index: {{#each array}} {{@index}}: {{this}} {{/each}} For object iteration, use @key instead: … Read more

Access properties of the parent with a Handlebars ‘each’ loop

There are two valid ways to achieve this. Dereference the parent scope with ../ By prepending ../ to the property name, you can reference the parent scope. {{#each items}} <div style=”font-size:{{../itemSize}}px”>{{this}}</div> {{#if this.items.someKey}} <div style=”font-size:{{../../itemSize}}px”>{{this}}</div> {{/if}} {{/each}} You can go up multiple levels via repeating the ../. For example, to go up two levels use … Read more

Is there a built-in way to loop through the properties of an object?

Built-in support since Handlebars 1.0rc1 Support for this functionality has been added to Handlebars.js, so there is no more need for external helpers. How to use it For arrays: {{#each myArray}} Index: {{@index}} Value = {{this}} {{/each}} For objects: {{#each myObject}} Key: {{@key}} Value = {{this}} {{/each}} Note that only properties passing the hasOwnProperty test … Read more

Handlebars/Mustache – Is there a built in way to loop through the properties of an object?

Built-in support since Handlebars 1.0rc1 Support for this functionality has been added to Handlebars.js, so there is no more need for external helpers. How to use it For arrays: {{#each myArray}} Index: {{@index}} Value = {{this}} {{/each}} For objects: {{#each myObject}} Key: {{@key}} Value = {{this}} {{/each}} Note that only properties passing the hasOwnProperty test … Read more

Logical operator in a handlebars.js {{#if}} conditional

This is possible by ‘cheating’ with a block helper. This probably goes against the Ideology of the people who developed Handlebars. Handlebars.registerHelper(‘ifCond’, function(v1, v2, options) { if(v1 === v2) { return options.fn(this); } return options.inverse(this); }); You can then call the helper in the template like this {{#ifCond v1 v2}} {{v1}} is equal to {{v2}} … Read more