@first : First Item
true for the first item in a `` loop, and false for the others.
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,
@firstand@lastare bothtrue. Outside a loop both arefalse. In nested loops each refers to the innermost loop. - Useful for separators, borders and headings that only belong on the first item.
@firstis added in Paperwork.Core 9.8. In earlier versions use{{#if @index == 0}}instead.