Array inputs

Last modified: September 11th, 2024

An Array input lets your team members create a list of inputs or grouped inputs. Array inputs can contain nested inputs of any type, including other Arrays and Objects. There is no limit to how many nested layers you can create within an Array. Creating a list of inputs, or input groups, is useful for organizing your data.

You can populate an Array input by defining an entry input type or by using predefined templates called structures. For more information on structures, please read our structures documentation.

For each input you can configure which structures are associated with the input, the appearance of the preview card, and how CloudCannon handles empty values. You can also use the general configuration options available for all inputs.

Array#

The Array input provides a user interface for lists of inputs or input groups. Each item in an Array is sometimes called an "entry". Entries in an Array can be a single value, an input, or an Object containing several inputs. Array inputs appear as a series of cards in the Data Editor or sidebar of the Visual or Content Editor.

A screenshot of the Array input in the Data Editor, showing a preview of the content within multiple entries.

For entries that use a key name (i.e., Objects, Arrays, or single inputs), the card will preview some of the content within the key. This can include images, strings, and key names. You can configure the preview settings for these cards.

Simpler entries with no key name, such as text, number, or boolean values, do not use cards. Instead, they appear as editable inline fields.

Array inputs can contain a mixture of inline fields and cards simultaneously.

A screenshot of the Array input in the Data Editor, showing multiple types of entries.

You can reorder, clone, add, and delete new entries in the list using the Context menu. You can also add new entries using the + Add button below the Array — the text on this button will differ depending on the key name of your input.

By default, adding a new entry to an Array input will clone the last entry in the Array.

A screenshot of the Array input in the Data Editor, showing the Context Menu with Add, Clone, Move, and Delete options.

When you click on a card in the Array, it will open to show the nested inputs within that Array entry. The Back button at the top of the entry will return you to the parent scope.

A screenshot of an open entry in an Array input in the Data Editor, showing the nested keys within this Object.

You can configure an Array input using the type key with the value array. Define the type key under your input key name within _inputs. For more information, please read our documentation on configuring your inputs.

cloudcannon.config.yaml
copied
_inputs:
  staff:
    type: array

All inputs are defined under the _inputs key, regardless of where they are in the configuration cascade.

This Array input is called staff.

The value of the type key determines the input type. This is an array input.

cloudcannon.config.json
copied
{
  "_inputs": {
    "staff": {
      "type": "array"
    }
  }
}

All inputs are defined under the _inputs key, regardless of where they are in the configuration cascade.

This Array input is called staff.

The value of the type key determines the input type. This is an array input.

For Array inputs to function correctly, they must contain at least one entry. You can add entries to an Array using the Source Editor. Alternatively, you can configure an entry input type or a structure to allow team members to populate the Array.

Once configured, the Array input will appear in the Data Editor or sidebar of the Visual or Content Editor when you add it to a data file or the front matter of a markup file.

page.md
copied
---
staff:
  - name: Karen Key
    position: Project Manager
    image: /images/team/karen_key.jpg
  - name: Holly James
    position: Engineering Team Lead
    image: /images/team/holly_james.jpg
---

Page content goes here.

Populating an Array input#

Without additional configuration, default Array inputs become misconfigured when empty.

In default Array inputs, CloudCannon will clone the last entry in the Array to add a new entry. This method is not possible with an empty Array. You can configure the entry input type or create a structure to avoid this issue and support empty Arrays.

Entry input type#

The entry input type defines what type of input CloudCannon should use to populate an Array or Object. Defining the entry input type for an Array input allows the Array to be empty without becoming misconfigured. All new entries added to an Array input will match the input type specified by the entry input type.

Array inputs with a defined entry input type avoid the issue of becoming misconfigured when empty. Because you have specified which input type to use in the Array, CloudCannon can repopulate the input if you delete the contents of the Array or create a new instance of that input.

A screenshot of an Array input in the Data Editor, containing only Image inputs.

You can configure the entry input type for your Array input under the _inputs key. To specify future entries within a particular Array, use the key name of the Array followed by the [*] characters. Define the type of input for those entries with the type key.

cloudcannon.config.yaml
copied
_inputs:
  gallery:
    type: array
  gallery[*]:
    type: image

The entry input type determines how CloudCannon should populate an Array input. The entry input type for the gallery Array is image inputs.

cloudcannon.config.json
copied
{
  "_inputs": {
    "gallery": {
      "type": "array"
    },
    "gallery[*]": {
      "type": "image"
    }
  }
}

The entry input type determines how CloudCannon should populate an Array input. The entry input type for the gallery Array is image inputs.

Structured Arrays#

A structured Array allows your team to select a predefined template to populate the inputs.

This input type relies on structures. For more information about how to configure structures, please read our structures documentation.

Structured Array inputs appear similar to the default input. However, unlike the default Array input, when you click the + Add button to add a new array entry, CloudCannon will prompt you to select which structure to use.

A screenshot of a structured Array input in the Data Editor, showing a dropdown menu to select the structure for a new entry.

Structured Array inputs avoid the issue of becoming misconfigured when empty. Because you have configured at least one structure and linked it to your input, CloudCannon can repopulate the input if you delete the contents of the Array or create a new instance of that input.

A screenshot of an empty structured Array input in the Data Editor, showing a dropdown menu to select the structure for a new entry.

You can configure an Array input using the structures key. Define the structures key under options within your input key name. The value of the structures key can be a string or an object.

If you have defined your structures elsewhere under the _structures key, you can reference it by using the key name as the value (i.e., _structures.key_name).

cloudcannon.config.yaml
copied
_inputs:
  staff:
    type: array
    options:
      structures: _structures.staff_members

This Object input is called staff.

The value of the type key determines the input type. This is an array input.

The structures option determines what should populate the input. In this case, it references the structure called staff_members defined under _structures elsewhere in the configuration cascade.

cloudcannon.config.json
copied
{
  "_inputs": {
    "staff": {
      "type": "array",
      "options": {
        "structures": "_structures.staff_members"
      }
    }
  }
}

This Object input is called staff.

The value of the type key determines the input type. This is an array input.

The structures option determines what should populate the input. In this case, it references the structure called staff_members defined under _structures elsewhere in the configuration cascade.

Alternatively, you create an Array called values to define your structures directly within your input configuration.

cloudcannon.config.yaml
copied
_inputs:
  staff:
    type: array
    options:
      structures:
        values:
          - label: Manager
            icon: face
            value:
              name: 
              job_description: 
              profile_picture: 
              url: 
          - label: Employee
            icon: support_agent
            value:
              name: 
              job_description: 
              profile_picture: 

This Object input is called feature_section.

The value of the type key determines the input type. This is an object input.

The structures option determines what should populate the input. In this case, it is an object containing the values Array. For more information about how to configure structures, please read our structures documentation.

cloudcannon.config.json
copied
{
  "_inputs": {
    "staff": {
      "type": "array",
      "options": {
        "structures": {
          "values": [
            {
              "label": "Manager",
              "icon": "face",
              "value": {
                "name": null,
                "job_description": null,
                "profile_picture": null,
                "url": null
              }
            },
            {
              "label": "Employee",
              "icon": "support_agent",
              "value": {
                "name": null,
                "job_description": null,
                "profile_picture": null
              }
            }
          ]
        }
      }
    }
  }
}

This Object input is called feature_section.

The value of the type key determines the input type. This is an object input.

The structures option determines what should populate the input. In this case, it is an object containing the values Array. For more information about how to configure structures, please read our structures documentation.

Options#

You can configure Array inputs using the options key under your input key, inside of _inputs.

cloudcannon.config.yaml
copied
page_sections: 
_inputs:
  page_sections:
    type: array
    options:
      structures: _structures.components
      preview:
        text:
          - key: name
        subtext:
          - key: description
        image:
          - key: my_image
        icon: article
      empty_type: string
cloudcannon.config.json
copied
{
  "page_sections": null,
  "_inputs": {
    "page_sections": {
      "type": "array",
      "options": {
        "structures": "_structures.components",
        "preview": {
          "text": [
            {
              "key": "name"
            }
          ],
          "subtext": [
            {
              "key": "description"
            }
          ],
          "image": [
            {
              "key": "my_image"
            }
          ],
          "icon": "article"
        },
        "empty_type": "string"
      }
    }
  }
}

Array inputs have the following options available:

structures — String or object#

This key determines which predefined templates to use for populating the Object Input. When configured, team members can select a structure to populate the Object with input/input groups. This key has no default.

If configured as an object, CloudCannon will use the values directly.

If configured as a string, CloudCannon will use the matching structures value defined under _structures in the configuration cascade.

preview — object#

This key enables you to define the appearance of the input in the Data Editor or sidebar of the Visual or Content Editor. The following nested keys are available:

  • text
  • subtext
  • icon
  • image

If the Array Input uses structures, CloudCannon will use the preview key from the structure instead.

For more information about previews, please read our documentation on configuring card previews.

preview.text — array, string, or boolean#

This key determines the title text displayed on a default Array Input card(s). This key has no default, and falls back to the first nested value found (prioritizing text-based values).

If set to false, no text is displayed.

preview.subtext — array, string, or boolean#

This key determines the subtitle text displayed on a default Array Input card(s). This key has no default, and falls back to listing the label of each nested input. subtext is hidden if text and subtext are the same. If there is no text, subtext will appear in the place of text.

If set to false, no text is displayed.

preview.icon — array, string, or boolean#

This key determines the icon displayed on a default Array Input card(s). The value must match a name from the Material Icons list. Defaults checking the icon key, then falls back to the notes icon.

If set to false, no icon is displayed.

If image is defined, the image replace icon when loaded successfully.

preview.image — array, string, or boolean#

This key determines the image displayed on a default Array Input card(s). This key has no default, and falls back to thumbnail_image, thumbnail_image_path, image, and image_path in that order. If no image is found, icon is displayed instead.

If set to false, no image is displayed.

empty_type — String#

This key determines how CloudCannon handles an empty value. This key does not apply to existing empty values.

Value must be one of the following:

  • string - an empty value for this input will be stored as "".
  • null - an empty value for this input will be stored as a null value (default). This does not apply to TOML files.

Unconfigured Array inputs#

In some cases, CloudCannon can still detect an Array input even if you have not configured it.

CloudCannon will interpret any unconfigured input with a list of nested values or keys as an Array input. You cannot create structured Array inputs without configuration.

data.yml
copied
animals:
  - bear
  - lizard
  - swan
  - name: Dog
    fun_fact: Man's best friend.
    image: /images/my-dog.png

This behavior is convenient if you have simple inputs or do not want to configure inputs. It is also beneficial for new websites on CloudCannon where you have yet to create any CloudCannon-specific configuration.

We recommend configuring your inputs for greater control over their functionality and appearance.

Related Articles

Related links

Open in a new tab