Skip to main content

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.

Note

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.

Note

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 value
    • set:[handle] - A Replicator or Bard set
    • row:[distill-type] - A Grid row (type can be defined in the field config)
    • node:[type] - A Bard node
    • mark:[type] - A Bard mark
    • entry:[collection] - An entry
    • term:[taxonomy] - A term
    • asset:[container] - An asset
    • user - A user
    • raw:[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 both max_depth and min_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:replicator
    • value:bard
    • value:grid
    • value:entries
    • value:terms
    • value:assets
    • value:users
    • raw:array
    • raw:object
  • unique (boolean, false)
    Filter out duplicate items. Filtering is only applied to these types:
    • entry
    • term
    • asset
    • user
  • 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 have enabled set to false, enabled sets have no enabled value 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 with limit.
  • sort (string)
    The sort order, a field name optionally followed by :asc or :desc. Multiple sorts can be pipe delimited. Use value to 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.