Distill Tag
The {{ distill }} tag runs a query against a value in the current context and loops over the items it finds. It works just like the collection tag, so you can filter, sort, limit and paginate the results in the same way.
Basic Usage
Pass the name of the variable you want to search as the second part of the tag name, or through the from parameter. These two are equivalent:
{{ distill:builder type="set:quote" }}
<blockquote>{{ text }}</blockquote>
{{ /distill:builder }}
{{ distill from="builder" type="set:quote" }}
<blockquote>{{ text }}</blockquote>
{{ /distill }}
The source can be any variable in the current context, a field, a raw array, or a whole entry, term, asset or user. {{ distill:page }} searches every field in the current entry.
It's the name of the variable that you pass, not the value itself. Distill looks the variable up in the context so it can work with the field's underlying data.
count, text and bard are tags of their own (Counting and Text & Bard), so a variable with one of those names has to be passed with from, as in {{ distill from="text" }}.
Inside the tag pair each item's own data is available, so a set gives you its fields, a Grid row its columns, an asset its url and so on. Individual field values and raw scalars are wrapped so they're available as {{ value }}. Every item also includes an info object.
Parameters
- from (string)
The name of the source variable (not the variable itself), can be a single field or raw value or an entry, term, asset or user. - type (string)
The type to match, asterisks can be used as a wildcard and multiple types can be pipe delimited, options are:value:[fieldtype]- A field valueset:[handle]- A Replicator or Bard setrow:[distill-type]- A Grid row (type can be defined in the field config)node:[type]- A Bard nodemark:[type]- A Bard markentry:[collection]- An entryterm:[taxonomy]- A termasset:[container]- An assetuser- A userraw:[php-type]- A raw value (inc. stdClass)class:[php-class]- Any other object (exc. stdClass)
- path (string)
The path to match, asterisks can be used as a wildcard and multiple paths can be pipe delimited, paths themselves are dot delimited. - depth (integer)
Sets bothmax_depthandmin_depth. - min_depth (integer)
The minimum depth to find items from. - max_depth (integer)
The maximum depth to find items from. Distill will stop walking at this depth. - expand (string, all)
Which types to expand and walk into, asterisks can be used as a wildcard and multiple types can be pipe delimited, options are:set:[handle]row:[distill-type]value:replicatorvalue:bardvalue:gridvalue:entriesvalue:termsvalue:assetsvalue:usersraw:arrayraw:object
- unique (boolean, false)
Filter out duplicate items. Filtering is only applied to these types:entrytermassetuser
- include_source (boolean, false)
Whether to include the source value itself as an item. - include_disabled (boolean, false)
Whether to include disabled Replicator and Bard sets. Included sets haveenabledset tofalse, enabled sets have noenabledvalue at all. - still (string)
Which still to apply, multiple stills can be pipe delimited. - limit (integer)
The maximum number of items. - offset (integer)
The starting item offset. - paginate (integer)
Enables pagination and sets the number of items per page. Can't be combined withlimit. - sort (string)
The sort order, a field name optionally followed by:ascor:desc. Multiple sorts can be pipe delimited. Usevalueto sort individual field values and raw scalars. - as (string)
Alias the items to a variable of your choosing, see below. - [conditions] (mixed)
Any where conditions, applied to the item's own data.
The Info Object
Each item includes an info object that describes it:
- type - Type of the item.
- name - Field handle or array key of the item within its parent.
- path - Path to the item from the source.
- source - Original source value.
- parent - The set, row or field that contains this item.
So you can find out where an item came from, link back to the source entry, or read a value from the set that contains it:
{{ distill:page type="asset:*" }}
<a href="{{ info:source:url }}#{{ info:parent:id }}">
{{ url }} found at {{ info:path }}
</a>
{{ /distill:page }}
The parent is itself an item, so it has its own info object too.
Aliasing and Pagination
By default the tag pair loops over the items directly. If you'd rather have them in a variable, so you can output something before and after the loop or check whether there were any results, use the as parameter. You'll also get total_results and no_results:
{{ distill:builder type="set:quote" as="quotes" }}
{{ if no_results }}
<p>No quotes.</p>
{{ else }}
<p>{{ total_results }} quotes</p>
{{ quotes }}
<blockquote>{{ text }}</blockquote>
{{ /quotes }}
{{ /if }}
{{ /distill:builder }}
When paginating the items are always aliased, to items unless you set as, and there's a paginate object with the same values as the collection tag's:
{{ distill:parts_list depth="1" paginate="10" }}
{{ items }}
{{ name }} {{ price }}
{{ /items }}
{{ paginate }}
<a href="{{ prev_page }}">←</a>
{{ current_page }} of {{ total_pages }}
<a href="{{ next_page }}">→</a>
{{ /paginate }}
{{ /distill:parts_list }}
Counting
The {{ distill:count }} tag returns the number of items a query would find, and accepts all the same parameters. Because the second part of the tag name is taken, the source has to be passed with from:
{{ distill:count from="builder" type="set:quote" }}
Like collection:count, it counts every match, so limit, offset and paginate don't apply.