Articles in this section

after helper

The after helper returns a new array that excludes the first n elements of the input array. Use it to skip leading items for pagination, offset handling, or trimming unwanted elements from the beginning of a list.

Syntax

{{after array n}}

array -- The array to slice. Required. Must be an array -- for other data structures, convert to an array first using the arrayify helper.

n -- The number of elements to skip from the beginning. Required. If n is greater than or equal to the array length, the helper returns an empty array.

Examples

Skip the first two elements

{{after record.letters 2}}

Input:

{
  "record": {
    "letters": ["a", "b", "c", "d"]
  }
}

Output: ["c", "d"]

Skip the first element

{{after record.items 1}}

Input:

{
  "record": {
    "items": ["apple", "banana", "cherry"]
  }
}

Output: ["banana", "cherry"]

Iterate over the remaining elements

{{#each (after record.tags 3)}}
  {{this}}
{{/each}}

Input:

{
  "record": {
    "tags": ["one", "two", "three", "four", "five"]
  }
}

Output:

four
five

Wrap after in a #each block to iterate directly over the returned array.

Usage notes

  • after works only with arrays. To use it with other data structures, convert them to an array first using the arrayify helper.
  • If n is greater than or equal to the array length, the helper returns an empty array.
  • after returns a new array and does not modify the original.