# Reference

Picks one or more entries from another collection, such as a post's author or a product's categories.

Add this field under `fields` in `.pages.yml`:

```yaml
- name: author
  type: reference
  options:
    collection: authors
```

A saved value in YAML or Markdown front matter might look like:

```yaml
author: src/content/authors/sam-lee.md
```

By default the entry's repository path is stored. Use `value` and `label` to store and show something else:

```yaml
- name: authors
  type: reference
  options:
    collection: authors
    multiple: true
    value: '{fields.name}'
    label: '{fields.name} ({fields.role})'
    search: fields.name,role
```

A saved value in YAML or Markdown front matter might look like:

```yaml
authors: [Sam Lee, Ana Silva]
```

If the site's schema uses Astro's `reference()`, it expects entry IDs, not repository paths. Choose a `value` template that produces the ID, such as a `slug` field the target entries share, and check a saved value against the site's schema.

## Options

| Option        | Description                                                                                  |
| ------------- | -------------------------------------------------------------------------------------------- |
| `collection`  | Required. The `name` of the collection to pick from.                                         |
| `value`       | Template for the stored value. Default `{path}`.                                             |
| `label`       | Template for what editors see. Default `{name}`, the filename.                               |
| `search`      | Comma-separated fields to search, such as `fields.name,email`. Default `name`, the filename. |
| `multiple`    | `true` to allow several entries, stored as a list.                                           |
| `min`, `max`  | With `multiple`, the minimum and maximum number of entries.                                  |
| `placeholder` | Text shown in the picker before anything is chosen.                                          |

## Template tokens

| Token              | Value                                                                                       |
| ------------------ | ------------------------------------------------------------------------------------------- |
| `{path}`           | The entry's file path in the repository                                                     |
| `{name}`           | The entry's filename, such as `sam-lee.md`                                                  |
| `{primary}`        | The entry's [primary field](/configuration/content/view/)                                   |
| `{locale}`         | The language, for [localized](/configuration/localization/) collections                     |
| `{fields.<field>}` | Any field, including nested ones such as `{fields.company.name}` or `{fields.links[0].url}` |
| `{<field>}`        | Shorthand for `{fields.<field>}` when the name isn't one of the tokens above                |

`{name}` is always the filename. To use a field called `name`, write `{fields.name}`. The same applies to `search`.

Changing `value` later doesn't update entries that already store the old format.
