@index : Item Position
The zero-based position of the current item in a `` loop.
Syntax
{{@index}}
Examples
Data:
builder.WithData("model", new {
items = new[] { new { name = "Widget" }, new { name = "Gadget" } }
});
Template:
{{#each model.items}}
<p>{{@index + 1}}. {{this.name}}</p>
{{#if @index == 0}}
<p>(our best seller)</p>
{{/if}}
{{/each}}
Output:
1. Widget
(our best seller)
2. Gadget
Notes
@indexstarts at0; add1for a count that starts at 1.- It can be used in any expression in the loop - calculations, conditions and attributes, e.g.
<rect y='{{@index * 30}}' />. - In a nested loop,
@indexis the position in the innermost loop.