I am trying to find a way to parse out differently depending array index as odd or even number
I was looking at this http://assemble.io/helpers/helpers-comparison.html and hope to find something like this:
{{#each array}}
{{#if_odd {{@index}}}}
{{this}} is odd
{{else}}
{{this}} is even
{{/if_odd}}
{{/each}}
I don't really care about the syntax but hope my idea comes across. Any help? Thanks.
{{if}} is used to check whether a field has a value or not, whereas {{compare}} is used to check whether a field has one value or another value. Check out our Handlebars helper reference for more information on handlebars {{compare}}, {{if}}, and other handlebars expressions!
A Handlebars helper call is a simple identifier, followed by zero or more parameters (separated by a space). Each parameter is a Handlebars expression that is evaluated exactly the same way as described above in "Basic Usage": template {{firstname}} {{loud lastname}}
The options -parameter In addition to the parameters used in the helper-call, an options -object is passed to the helper as additional parameter. lookupProperty(object, propertyName) : a function that returns an "own property" of an object.
You can register expression Helper by using the following code: Handlebars. registerHelper("last", function(array) { return array[array. length - 1]; });
I created this helper and it worked
Handlebars.registerHelper('if_even', function(conditional, options) {
if((conditional % 2) == 0) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
Just followed conditional helper here http://handlebarsjs.com/block_helpers.html
I tried to do this based on mu is too short
suggestion:
{{#if_even @index}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With