Skip to content

Getting started ​

Field Item Relationship adds one fieldtype to Statamic. It does not store content of its own. It points at an item in another field (the source field) and saves a reference to it.

Some typical uses:

  • Pick the main image from the entry's own gallery (an Assets field), shown as a thumbnail grid.
  • Pick the team lead from a Grid of team members.
  • Pick one of the brand colours defined in a List on a Global set.
  • Pick the cover of a gallery block inside a Replicator, from that block's own images.

Requirements ​

Version
PHP8.3 or newer
Statamic6.0 or newer (6.44+ for the image grid)
Statamic versionAdd-on versionBranch
Statamic 3, 4, 51.x1.x
Statamic 62.xmain

Installation ​

bash
composer require eminos/statamic-field-item-relationship

The add-on registers itself, and there is nothing to publish or configure. The fieldtype is listed as Field Item Relationship in the Relationship category of the blueprint editor, and its handle is field_item_relationship.

Your first field ​

We'll build the "team lead" example: a Grid of team members and a field that picks one of them.

1. Add a source field ​

Any field that stores a list can be a source. Here it is a Grid called team:

yaml
- handle: team
  field:
    type: grid
    display: Team
    fields:
      - handle: name
        field: { type: text, display: Name }
      - handle: role
        field: { type: text, display: Role }
      - handle: email
        field: { type: text, display: Email }
      - handle: photo
        field: { type: assets, display: Photo, container: assets, max_files: 1 }

2. Add a Field Item Relationship field ​

Add a Field Item Relationship field to the same blueprint and fill in the settings:

SettingValueWhy
Source fieldteamThe handle of the Grid.
Option label sourcenameWhich key of each row to show as the label.
Option image sourcephotoOptional: shows each person's photo as a thumbnail.
Save asItem IDSaves the row's ID, so renaming or reordering people keeps the selection.
Input typeImage gridShows the rows as clickable tiles.

In YAML that is:

yaml
- handle: team_lead
  field:
    type: field_item_relationship
    display: Team lead
    source_field: team
    option_label_source: name
    option_image_source: photo
    save_as: id
    input_type: image_grid
    columns: 4
    aspect_ratio: 1/1

Open an entry and you get a picker that is built from the Grid above it. Add a row to the Grid and it shows up in the picker straight away, before you save.

The team lead field as an image grid, built from the Team Grid rows, with Alice selectedThe team lead field as an image grid, built from the Team Grid rows, with Alice selected

Grid rows become image tiles when an Option image source is set.

3. Use it in a template ​

The field saves a reference (here, the row ID). The fir tag turns that back into the row:

antlers
{{ fir:team_lead }}
  <p><strong>{{ name }}</strong>, {{ role }} · {{ email }}</p>
{{ /fir:team_lead }}

{{# Or grab a single value #}}
<p>Lead: {{ fir:team_lead:name }}</p>

If the source is an Assets field, you don't need the tag

Fields that pick from an Assets field are augmented to real Asset objects, so hero_image:url, hero_image:alt and Glide work directly. See Assets as source.

Next steps ​

Released under the MIT License. Made with fruit by kiwikiwi