Articles in this section

pluck helper

The pluck helper iterates over an array (or array of objects) and returns a new array containing the values of a specified property for each element. It supports dot notation to access nested fields.

Usage

{{pluck array "property"}}
  • array (required): The array or object to extract values from

  • property (required): The property name to extract; supports dot notation

Examples

Extract a nested property from an array of objects

{{pluck record.items "data.title"}}

Input:

{
  "record": {
    "items": [
      {
        "data": {
          "title": "Introduction to Handlebars",
          "category": "Tutorial"
        }
      },
      {
        "data": {
          "title": "Advanced Template Logic",
          "category": "Guide"
        }
      },
      {
        "data": {
          "title": "Using Helpers Effectively",
          "category": "Best Practices"
        }
      }
    ]
  }
}

Output:

["Introduction to Handlebars", "Advanced Template Logic", "Using Helpers Effectively"]

Extract top-level values

{{pluck record.products "sku"}}

Input:

{
  "record": {
    "products": [
      { "sku": "A001", "price": 20 },
      { "sku": "A002", "price": 30 },
      { "sku": "A003", "price": 25 }
    ]
  }
}

Output:

["A001", "A002", "A003"]
Tips

Tip

  • Dot notation allows extracting deeply nested values (e.g., "order.customer.name").

  • Nonexistent properties return null for those array elements.

  • Combine with helpers like unique or join to further process the extracted values.