Handlebars filter
Handlebars filter: keeps only the list items that pass a field/operator/value test.
Next
Verification in progress
Differs from official docs
Test scripts included
Keeps only the list items that pass a field/operator/value test.
Syntax
{{filter list fieldName comparisonOperator targetValue filterAs}}
Returns array.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
list |
array | Yes | List of objects to check. |
fieldName |
string | Yes | Name of the field to compare. |
comparisonOperator |
string | Yes | Comparison operator (e.g. >, ==, CONTAINS). |
targetValue |
any | Yes | Value the field is compared with. |
filterAs |
string | Yes | The type to filter as: string, number, or date. |
Example
Tested in a Marketing Cloud Next email on 2026-11-25, alone in the email, with a list of objects built in AMPscript (Handlebars reads it as variable rows):
%%[ SET @rows = BuildRowsetFromJSON('[{"name":"Bob","age":27},{"name":"Ann","age":21},{"name":"Cid","age":24}]', '$[*]', 1) ]%%{{#each (filter rows "age" ">" 22 "number")}}[{{name}}]{{/each}}fails the email preview with HTTP 500. The documented result is[Bob][Cid]. The samerowsrender witheachand withsort.{{#each (filter (jsonpath '[{"name":"Bob","age":27},{"name":"Ann","age":21}]' "$") "age" ">" 22 "number")}}[{{name}}]{{/each}}also fails the preview with HTTP 500, as do a string comparison ("name" "==" "Ann" "string") and the documented chainmap (filter …) "name". The samejsonpathlist renders witheach.{{#if false}}{{filter myList "age" ">" 25 "number"}}{{/if}}is accepted when the email is saved.
Show Next test script
Show calls that fail in Next (one email each)
Differs from official docs
- The reference shows
{{filter myList "age" ">" 25 "number"}}returning the matching objects. In Marketing Cloud Next (tested 2026-11-25): the same call form on a list of objects built with AMPscriptBuildRowsetFromJSONfailed the email preview with HTTP 500, althougheachandsortread that list. Lists built withjsonpathfail the same way. Details
Marketing Cloud Next
Differs from the documentation
The documented call form fails the email preview with HTTP 500 on a list of objects built in AMPscript, and on a list built with jsonpath, although each, sort and map read the same lists. Tested 2026-11-25 by rendering in a Marketing Cloud Next email.