@last : Last Item
true for the last item in a `` loop, and false for the others.
Syntax
{{@last}}
{{#if @last}}...{{/if}}
Examples
Data:
builder.WithData("model", new {
items = new[] { new { name = "Widget" }, new { name = "Gadget" }, new { name = "Gizmo" } }
});
Template:
{{#each model.items}}
<span>{{this.name}}</span>
{{#if !@last}}<span>, </span>{{/if}}
{{/each}}
Output:
Widget, Gadget, Gizmo
Notes
- Equivalent to
@index == count(collection) - 1. - 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 last item.
@lastis added in Paperwork.Core 9.8. In earlier versions use{{#if @index == count(model.items) - 1}}instead.