The before helper returns a new array excluding the last n elements from the input array. Use it to remove trailing elements or to select only the first portion of an array.eturns a new array excluding the last n elements from the input array.
{{before array n}}
-
array (required): The array to slice
-
n (required): The number of items to exclude from the end
Exclude the last two elements
{{before record.letters 2}}
Input:
{
"record": {
"letters": ["a", "b", "c", "d"]
}
}
Output:
["a", "b"]
Keep only the first item
{{before record.items 3}}
Input:
{
"record": {
"items": ["apple", "banana", "cherry", "date"]
}
}
Output:
["apple"]
Use with iteration
{{#each (before record.tags 1)}}
{{this}}
{{/each}}
Input:
{
"record": {
"tags": ["draft", "review", "published"]
}
}
Output:
draft review
Tip
-
If n is greater than or equal to the array length, the helper returns an empty array.
-
Works only with arrays; for strings, use substring-related helpers instead.
-
Useful for trimming arrays before further processing or output.