Skip to content

Save as modes ​

Save as decides what is written to the entry when an editor picks an item. It is a trade-off: some modes keep working when the source is reordered, others when an item is renamed.

Which modes fit which source ​

Source dataExample fieldsAllowed modes
List of stringsList, Checkboxesvalue, index
List of objectsGrid, Replicatorindex, id, object_key, object
Object (key → value)Arraykey, value
AssetsAssetsvalue (recommended), index

If Save as doesn't fit the source data, the field shows a warning that names the modes to use. See Troubleshooting.

The modes ​

Modesave_asSaved valueSurvives reorderingSurvives renaming
KeykeyThe key of an Array item, e.g. expressyesif the key is unchanged
ValuevalueThe string, Array value or asset IDyesno
IndexindexPosition in the source, e.g. 2noyes
Item IDidThe row's id, e.g. mf3k2a9xyesyes
Object keyobject_keyThe value of one key, e.g. alice@example.comyesif that key is unchanged
ObjectobjectA copy of the whole rowyesdepends on Object key

Key ​

For keyed Array sources. Saves the array key (express). The label shown to editors is the value (Express shipping).

Value ​

For lists of strings, keyed Arrays and Assets. Saves the item itself: the string, the Array value, or the asset ID (assets::demo/photos/sunset.jpg).

If editors rename an item in the source (for example "Medium" to "M"), saved values that pointed at the old name no longer match.

Lists of objects

value is not allowed for Grid or Replicator sources. To store the whole row, use object.

Index ​

Saves the position (0, 1, 2…). Renaming an item is fine, but reordering, inserting or deleting items in the source makes the saved index point at a different item. Use it only for sources whose order doesn't change, or when "the item in this position" is really what you mean.

yaml
sizes_checkboxes: [0, 2]   # multiple + index

Item ID ​

For Grid and Replicator sources. Saves the row's id, which Statamic gives each row. This is the most robust choice for rows: the selection survives reordering, renaming and edits to any field in the row.

yaml
- handle: editor
  field:
    type: field_item_relationship
    source_field: team
    save_as: id
    option_label_source: '`${o.name} — ${o.role}`'

Object key ​

For Grid and Replicator sources. Saves the value of the key you set in Object key (object_key, dot notation allowed). Pick a key that is unique and doesn't change, such as an email address or a slug.

yaml
- handle: reviewers
  field:
    type: field_item_relationship
    source_field: team
    save_as: object_key
    object_key: email
    multiple: true
    max_items: 3

Object ​

Saves a copy of the whole row in the entry.

  • With Object key set, the row is matched again by that key, both in the control panel and in templates. The fir tag returns the current row from the source, and falls back to the saved copy if the row is gone.
  • Without an Object key, the control panel matches on the exact content, so any edit to the row loses the selection. The tag returns the saved copy.
yaml
- handle: spotlight
  field:
    type: field_item_relationship
    source_field: team
    save_as: object
    object_key: name
    input_type: button_group
    option_label_source: name

Which one should I pick? ​

  • Assets: value.
  • List of strings: value if items are rarely renamed, index if they are rarely reordered.
  • Keyed Array: key.
  • Grid / Replicator rows: id. Use object_key if you want a readable value in the content file (such as an email).

Labels with string literals ​

The label doesn't affect what is saved, but it is set next to Save as. Option label source takes a key (dot notation allowed), or a JavaScript template literal in back ticks, where o is the item:

yaml
option_label_source: '`${o.city}, ${o.country}`'

Dropdown labels built from two keys, "Alice — Design lead"Dropdown labels built from two keys, "Alice — Design lead"

`${o.name} — ${o.role}`

Released under the MIT License. Made with fruit by kiwikiwi