I have a Handlebars template that inserts an img element on my page. The image URLs come from an array that can have up to 8 items, but I only want to insert the first 4.
A simple {{#each}} block like this inserts an img for every item:
{{#each items}}
<img src="{{item.url}}" />
{{/each}}
How do I "stop" the {{#each}} after the first 4 items? Or, put another way, how do I tell it to only insert the img element if its index in the array is less than 4 (0 through 3)?
I know I can output the current index with {{@index}}, but I can't seem to use that within an {{#if}} block. In other words, this doesn't work:
{{#each items}}
{{#if {{@index}} < 4}}
<img src="{{item.url}}" />
{{/if}}
{{/each}}
What do I do instead?