---
title: Examples
order: 60
---

# Examples

[TOC]

---

## Finding Things

### Find every image in the page

```antlers
{{ distill:page type="asset:*" is_image:is="true" unique="true" }}
    <img src="{{ url }}" alt="{{ alt }}">
{{ /distill:page }}
```

### Find the first image in the page

```antlers
{{ distill:page type="asset:*" is_image:is="true" limit="1" }}
    <meta property="og:image" content="{{ permalink }}">
{{ /distill:page }}
```

### Find every entry linked from anywhere in the page

```antlers
{{ distill:page type="entry:*" unique="true" }}
    <a href="{{ url }}">{{ title }}</a>
{{ /distill:page }}
```

### Find every link in a Bard field

```antlers
{{ distill:content type="mark:link" }}
    {{ attrs:href }}
{{ /distill:content }}
```

### Find every heading in a Bard field

```antlers
{{ distill:content type="node:heading" }}
    <a href="#{{ content | bard_text | slugify }}">{{ content | bard_text }}</a>
{{ /distill:content }}
```

### Find one kind of set in a page builder, however deeply nested

```antlers
{{ distill:builder type="set:cta" }}
    <a href="{{ url }}">{{ label }}</a>
{{ /distill:builder }}
```

### Find sets that match a condition

```antlers
{{ distill:builder type="set:section" featured:is="true" }}
    <h2>{{ heading }}</h2>
{{ /distill:builder }}
```

---

## Text

### Extract all Bard text from a page builder

```antlers
{{ { distill:bard from="builder" } | bard_text }}
```

### Build a meta description from the page content

```antlers
<meta name="description" content="{{ { distill:text from="builder" max_depth="3" } | safe_truncate:160 }}">
```

---

## Grids and Arrays

### Filter, sort and paginate a Grid field

```antlers
{{ distill:parts_list depth="1" paginate="10" :category:is="get:category" :sort="get:sort" }}
    {{ items }}
        {{ name }} {{ price }}
    {{ /items }}
    {{ paginate }}
        <a href="{{ prev_page }}">←</a>
        <a href="{{ next_page }}">→</a>
    {{ /paginate }}
{{ /distill:parts_list }}
```

### Query a raw array

A raw array or object in the context, such as one passed to the view, is walked just like a field, with each element typed as `raw:*`. Scalars are wrapped so their value is available as `value`:

```antlers
{{ distill:sizes type="raw:string" sort="value" }}
    <span>{{ value }}</span>
{{ /distill:sizes }}
```

---

## In PHP

### Find every video set in an entry

```php
use JackSleight\StatamicDistill\Facades\Distill;

$videos = Distill::query($entry)
    ->type('set:video')
    ->where('url', 'like', '%youtube.com%')
    ->get();
```

### Refactor nested content

Because every item comes back with its path, you can use Distill to find old sets or fields in your content and then update them in place. There's a full walkthrough in [Refactoring Statamic content with Distill](https://jacksleight.com/blog/refactoring-statamic-content-with-distill).
