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

@first : First Item

true for the first item in a `` loop, and false for the others.


On this page

Syntax

{{@first}}
{{#if @first}}...{{/if}}

Examples

Data:

builder.WithData("model", new {
    items = new[] { new { name = "Widget" }, new { name = "Gadget" }, new { name = "Gizmo" } }
});

Template:

{{#each model.items}}
    {{#if !@first}}<span>, </span>{{/if}}
    <span>{{this.name}}</span>
{{/each}}

Output:

Widget, Gadget, Gizmo

Notes

  • Equivalent to @index == 0.
  • Works in output, in `` conditions, in functions such as {{if(@last, '.', ',')}}, and in CSS expressions inside the loop.
  • With a single item, @first and @last are both true. Outside a loop both are false. In nested loops each refers to the innermost loop.
  • Useful for separators, borders and headings that only belong on the first item.

@first is added in Paperwork.Core 9.8. In earlier versions use {{#if @index == 0}} instead.


See Also