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

@last : Last Item

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


On this page

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, @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 last item.

@last is added in Paperwork.Core 9.8. In earlier versions use {{#if @index == count(model.items) - 1}} instead.


See Also