The #inArray block helper checks whether a specified value exists in an array and renders one expression if found, or an optional {{else}} expression if not. The helper works only with simple arrays (strings, numbers) -- not arrays of objects.
Syntax
{{#inArray array value}} expr {{else}} expr {{/inArray}}
array -- The array to search. Required. Must be a simple array of strings or numbers.
value -- The value to search for. Required. Matching is case-sensitive and type-sensitive -- the string "3" does not match the integer 3.
Examples
Route based on an order tag
{{#inArray record.order.tags "priority"}}
Push to Salesforce as high-priority case
{{else}}
Ignore or send as regular case
{{/inArray}}
Input:
{
"record": {
"order": {
"id": 45678,
"tags": ["gift", "priority", "international"]
}
}
}
Output: Push to Salesforce as high-priority case
Return the else branch when the value is absent
{{#inArray record.order.tags "express"}}
Mark as express shipping
{{else}}
Continue with standard shipping
{{/inArray}}
Input:
{
"record": {
"order": {
"tags": ["gift", "priority", "international"]
}
}
}
Output: Continue with standard shipping
Type mismatch returns no match
{{#inArray record.numbers "3"}}Found{{else}}Not found{{/inArray}}
Input:
{ "record": { "numbers": [1, 2, 3, 4] } }
Output: Not found
The array contains the integer 3, but the search value is the string "3". Because matching is type-sensitive, no match is found.
Usage notes
- Matching is case-sensitive:
"Priority"and"priority"are treated as different values. - Matching is type-sensitive: the string
"3"does not match the integer3. - If
arrayis not a valid simple array, or if it contains objects, the{{else}}branch renders. - For arrays of objects, use the #filter helper instead.