Skip to main content Link Search Menu Expand Document Toggle dark mode Copy Code (external link)
paperwork.help

@index : Item Position

The zero-based position of the current item in a `` loop.


On this page

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

  • @index starts at 0; add 1 for 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, @index is the position in the innermost loop.

See Also