Using handlebars templates is there a way to render logic if looping over not the last item in an array?

204 Views Asked by At

Using java handlebars 4.2.1 https://github.com/jknack/handlebars.java is there a way to render logic if looping over not the last item in an array?

I know that I can do this:

{{#myArray}}
{{#if @last}}
{{else}}
  my rendered logic here
{{/if}}
{{/myArray}}

But I am looking for something with only one block, similar to {{^-last}} from mustache templates

1

There are 1 best solutions below

0
On

It looks like one can do this with the unless helper:

{{#myArray}}
{{#unless @last}}
  my rendered logic here
{{/unless}}
{{/myArray}}

Per their docs You can use the unless helper as the inverse of the if helper. Its block will be rendered if the expression returns a falsy value.