Skip to main content

Introduction

This Statamic addon allows you to filter, fetch or index the individual values, sets and relations within your entries, from both root and deeply nested fields. It's useful for things like:

  • Extracting the text from every Bard field within a replicator
  • Finding every asset in the page, or just the first image
  • Filtering, sorting and paginating a Grid field or raw array just like a collection
  • Adding individual sections of a page to a search index
  • Refactoring nested data and sets

How It Works

Distill recursively walks through the value you give it looking for items that match your criteria. It can find individual paragraphs and field values through to entire sets and references to other content, from anywhere in the hierarchy, and returns them all as one flat list.

Every item comes back with its own data, so a set gives you its fields and an asset gives you its URL, plus an info object that tells you what it is and where it came from. Each item is given a type like set:hero or asset:images, and a path like builder.2.image.0, and those two things are how you narrow down what you're looking for.

You can start from a whole entry, term, asset or user, from a single field value, or from a raw array or object.

Performance

For optimal performance you should use the type, path, expand, limit and max_depth parameters to restrict where Distill goes based on what you're looking for. These options don't just filter the final result, they tell Distill where to look and when to stop, so a well targeted query does a lot less work than a broad one.

Loading related entries, terms, assets and users is the most expensive part of a walk, so Distill skips it entirely when your type can't match one of those. A query for set:* will never load an asset.

Limitations

There are a couple of things Distill deliberately won't do:

  • It will find references to other entries, terms, assets and users, but it won't walk into those objects. Only the source of the query has its fields walked.
  • It will only walk raw arrays and objects if you pass one in as the source. It won't walk into a field's raw value, so an array or list field is treated as a single value.