check collection size in each iteration

17 views
Skip to first unread message

devinpain

unread,
Apr 24, 2017, 12:49:27 PM4/24/17
to handlebars.java
Hi,

I am trying to do a simple thing, and really struggling to see how this would work...

in a hbs template, I am producing some json by iterating over a collection.

{{#each items}}
"id": {{id}},
"discount": {{#if ../items 'gt' 1}}1{{/if}}
{{/each}}

How would you output the discount so that the value is either 0 when the items collection size is 1 or '1' if the items collection is greater than 1?

I am struggling to find a way despite looking at the documentation. This is using the java version of handlebars.... (latest version)...

Thank you.

Y
Reply all
Reply to author
Forward
0 new messages