Articles in this section

#filter helper

Checks each element in an array and renders the block for each element whose value/property equals the specified value; if no matches, renders the {{else}} block. the specified value. If no matches are found, the {{else}} block is rendered. This helper is useful when working with arrays of objects where filtering by property is required.

Usage

{{#filter array value arrayProperty}}expressionInitial{{else}}expressionElse{{/filter}}
  • array (required): array to filter

  • value (required): value to match

  • arrayProperty (optional): property in each array element to compare (if array contains objects)

Examples

  1. Filter order line items by tag

{{#filter record.order.lineItems "custom" "tag"}}
  Custom item: {{sku}}
{{else}}
  No custom items
{{/filter}}

Input:

{
  "record": {
    "order": {
      "id": 12345,
      "customer": "John Doe",
      "lineItems": [
        { "sku": "TShirt-001", "tag": "standard" },
        { "sku": "Mug-009", "tag": "custom" },
        { "sku": "SmallMug-010", "tag": "custom" },
        { "sku": "Cap-003", "tag": "standard" }
      ]
    }
  }
}

Output:

Custom item: Mug-009
Custom item: SmallMug-010
  1. Check for non-matching case

{{#filter record.order.lineItems "express" "tag"}}
  Found express items
{{else}}
  No express items
{{/filter}}

Output:

No express items

Tip

  • The match is case-sensitive: "Custom" and "custom" are treated differently.

  • Inside the block, you can directly access the properties of the matching element (e.g., {{sku}}, {{tag}}).

  • #filter renders once per match. Use it when you need to output properties of the matched element(s).

  • Works with primitive arrays and arrays of objects.

  • arrayProperty supports dot-paths (e.g., "details.department").

  • If the first argument is missing/undefined/not an array, the helper produces no output (does not hit {{else}}).

  • An empty array [] (valid but with no elements) will render the {{else}} block.