Choose your preferred SSG:
Choose your preferred SSG:

Using Array Inputs to edit your data

These inputs are for editing ordered lists of values in your data.

Array inputs are grouped lists of inputs in the data editor. They are used for a wide range of use cases, ranging from small text lists to full component builders. Array inputs give your editors:

  • Drag and drop reordering
  • Configurable add options at any index
  • Intuitive editing
  • Easy removal of items

Array

Grouped list of inputs with controls to add, remove and reorder items.

Array inputs are shown for inputs configured with the type array, or for array input values.

Inline values

Inline values in Array inputs are displayed and edited with inputs directly in the list. By default, text, number and boolean values are displayed inline as text, number and checkbox inputs.

The array editor with draggable handles, editable text and an option to add new content.
Value convention
staff:
  - Bill
  - Ben
  - Badger
Input configuration
sections:
_inputs:
  sections:
    type: array

You can configure arrays to use different inputs for inline values with input configuration. Each value is still stored as either a text, number or boolean value — but is now edited with a more suitable input.

Here’s an example for an array of Image File inputs:

Input configuration
gallery:
  - /uploads/mountain.png
  - /uploads/beach.png
_inputs:
  gallery:
    type: array
  gallery[*]:
    type: image
    

Here’s another example for an array of Select inputs, populated from a posts collection:

Input configuration
other_posts:
  - /posts/top-10-things.md
  - /posts/yesterday-i-found.md
_inputs:
  other_posts:
    type: array
  other_posts[*]:
    type: select
    options:
      values: collections.posts

Structured or nested values

Array inputs containing object or array values are shown as a list of Object inputs. Team members add, remove or reorder items directly on this input. Item values are edited after opening each item.

This allows your team members to intuitively manage complex data. When your data can be deeply nested, there is no end to what can be achieved. Rendering the array value from this input with a loop on your site creates powerful editing opportunities for your team members.

The array editor with a list of staff members including their thumbnail image and name
The array editor with a list of staff members including their thumbnail image and name
Value convention
quotes:
  - name: 'Betty Jefferson'
    position: 'Jamstack Developer'
    image: /images/betty.svg
    quote_markdown: '“This quotation can be edited via the front matter textarea input.”'
  - name: 'Jamie Mills'
    position: 'Jamstack Developer'
    image: /images/jamie.svg
    quote_markdown: '“You can also reorder quotations via the front matter arrays input.”'

Options

Array inputs are configured with options inside an _inputs entry.

Input configuration
page_sections:
_inputs:
  page_sections:
    type: array
    options:
      structures: _structures.components
      preview:
        text:
          - key: name
        subtext:
          - key: description
        image:
          - key: my_image
        icon: article

Array inputs have the following options available:

empty_type - string

Set how an ‘empty’ value will be saved. Does not apply to existing empty values. Can be one of the following:

  • array - an empty value for this input will be stored as [] (default).
  • null - an empty value for this input will be stored as a null value. This does not apply to TOML files.
preview - Object

The preview definition for changing the way data within an Array input’s items are previewed before being expanded. The options available for Array inputs are:

  • text
  • subtext
  • icon
  • image

See the preview options documentation for detailed information on setting this option.

If the input has structures, the preview from the structure definition is used instead for those items.

preview.icon - Array, string or boolean

Controls the icon shown on the unopened item inputs. Must match a Material Icon name. Defaults checking the keys thumbnail_image, thumbnail_image_path, image, and image_path in that order, then falls back to notes.

If set to false, no icon is displayed.

If image is set, it will cover icon when loaded successfully.

preview.image - Array, string or boolean

Controls the image shown on the unopened item inputs. Has no default, falls back to thumbnail_image, thumbnail_image_path, image, and image_path in that order.

If set to false, no image is displayed.

If no image is found, icon is displayed instead.

preview.subtext - Array, string or boolean

Controls the supporting text shown on the unopened item inputs. Has no default, falls back to listing the label of each input inside the object value.

If set to false, no text is displayed.

Subtext is hidden if text and subtext is the same. If there’s no text, subtext is used instead.

preview.text - Array, string or boolean

Controls the main text shown on the unopened item inputs. Has no default, falls back to the first value found (prioritizing text-based values).

If set to false, no text is displayed.

structures - String or object

Provides options for creating new items. When adding a new item, team members are prompted to choose from a number of values you have defined. Defaults to fetching from _structures using the naming convention (e.g. _structures.blocks for an input key blocks).

If set as an object, the structures value is used directly.

if set as a string, the structures value is fetched from the configuration cascade. This allows you to define _structures elsewhere and reference it from here.

Was this article helpful? or Suggest an improvement >

Related articles

Other Resources

  1. Material Icons