The arrayify helper casts any value into an array. Use it to normalize fields that may contain either a single value or an array so that downstream helpers like #each can process them consistently.
- If the input is already an array, it's returned unchanged.
- If the input is a single value, it's wrapped in a single-element array.
- If the input is
null,undefined, or a missing field, it returns an empty array[].
Syntax
{{arrayify value}}
value -- The value to cast into an array. Required. Accepts any type: string, number, array, null, or undefined.
Examples
Wrap a single value and pass through an existing array
{{arrayify record.name}}
{{arrayify record.tags}}
Input:
{
"record": {
"name": "foo",
"tags": ["promo", "sale"]
}
}
Output:
["foo"] ["promo", "sale"]
record.name is a string, so it's wrapped in an array. record.tags is already an array, so it passes through unchanged.
Return an empty array for a missing field
{{arrayify record.missingField}}
Input:
{ "record": {} }
Output: []
record.missingField is undefined, so the helper returns an empty array rather than null or an error.
Wrap a comma-separated string as a single element
{{arrayify record.test}}
Input:
{ "record": { "test": "a,b" } }
Output: ["a,b"]
arrayify wraps the entire string as one element -- it does not split on commas or other delimiters. To split a delimited string into multiple array elements, use the split helper first.
Usage notes
- Use
arrayifybefore#eachwhen a field may contain either a single value or an array -- this prevents the loop from failing or iterating over individual characters of a string. -
arrayifydoes not split delimited strings."a,b"becomes["a,b"], not["a", "b"]. - A missing or undefined field returns
[], not an error, making it safe to use on optional fields.