Some webpages, or webpage components, are constructed from arrays. An array is an ordered list of data, where data is grouped into array items. Each array item could contain one or several structured data keys.
Arrays can be simple, where each item has the same structure (e.g., a testimonial component), or more complex, where each item has a different structure (e.g., a page with various components). For simple arrays, you can use Array Editable Regions A designated area within a webpage where Organization Members can add, remove, and reorder array values in CloudCannon's Visual Editor. Array Editable Regions work with arrays stored in structured data or front matter that populate templating in your layout files, and support editing array components and page building. A designated area marking a single item inside an Array Editable Region, which Organization Members can move, duplicate, or remove in CloudCannon's Visual Editor, or use to add a new item after it. Each Array Item Editable Region must sit within an Array Editable Region, and can contain nested Editable Regions for editing the content of that item.Array Editable Region
Array Item Editable Region
Nested text or image values in an array
To avoid data-prop misconfiguration errors, it is best practice to define your Editable Regions from the root of your file first (i.e., from parent elements to child elements). If you want to edit text or image values in an array using the Visual Editor, you should define your Array and Array Item Editable Regions on the parent element before Text and Image.
Arrays with identical array items#
Array content is defined using structured data keys in the front matter of hybrid files (e.g., .mdx) or in data files (e.g., .yml) and referenced by templating in a layout file. Simple arrays have the same structured data keys for every array item.
Let's take a look at an example.
Our website has a "Testimonials" page, where we display testimonials from customers. The page content is stored in the front matter of a Markdown file and populates a layout file.
Here is our content file, testimonials.md, containing the testimonials array with structured data keys for image, image_alt, name, job_title, and quote in each array item.
---
layout: ../layouts/TestimonialsLayout.astro
testimonials:
- image: ../../assets/placeholder-1.jpg
image_alt: Profile photo of D. Gale
name: D. Gale
job_title: CEO at Yellow Brick Industries
quote: >-
"In pretium libero sed velit posuere sagittis."
- image: ../../assets/placeholder-2.jpg
image_alt: Profile photo of S. Crow
name: S. Crow
job_title: CBO at Yellow Brick Industries
quote: >-
"Mauris at augue quis orci egestas eu in nulla."
- image: ../../assets/placeholder-3.jpg
image_alt: Profile photo of T. Man
name: T. Man
job_title: CHO at Yellow Brick Industries
quote: >-
"Nunc ut sem vitae tortor volutpat varius."
- image: ../../assets/placeholder-4.jpg
image_alt: Profile photo of C. Lion
name: C. Lion
job_title: CCO at Yellow Brick Industries
quote: >-
"Aenean pharetra orci ac tincidunt lobortis."
---Here is an excerpt from our layout file, TestimonialsLayout.astro. This section loops over all the items in the testimonials array, and populates the layout using the values.
---
const { testimonials } = Astro.props.frontmatter;
---
<ul>
{
testimonials.map((testimonial) => (
<li>
{testimonial.image && (
<img
src={testimonial.image}
alt={testimonial.image_alt}
/>
)}
<h4>{testimonial.name}</h4>
<p>{testimonial.job_title}</p>
<p>{testimonial.quote}</p>
</li>
))
}
</ul>This <img> element contains image source and alt text attributes. The src and alt attributes are set to the template {testimonial.image} and {testimonial.image_alt} respectively.
This <h4> element surrounds the template value {testimonial.name}.
This <p> element surrounds the template value {testimonial.job_title}.
This <p> element surrounds the template value {testimonial.quote}.
Together, these files output a webpage that looks like this:

To enable visual editing for this array, we can add Array and Array Item Editable Regions to our layout file. Array Editable Regions define the boundary of the array, and Array Item Editable Regions define each array item. Array and Array Item Editable Regions work together, so we must always have both.
The <ul> element wraps the array in our layout file, with its contents looping over every array item stored under the testimonials key. To define an Array Editable Region, let's add the data-editable and data-prop HTML attributes to the <ul> DOM element. The data-editable HTML attribute defines which type of Editable Region you want to use which, in this case, is array. Alternatively, we could choose to wrap the array templating in the equivalent web component <editable-array>, however that is not as convenient as adding attributes to existing elements. Our Array Editable Region also needs a data-prop to define where our array data is stored which, in this case, will be the testimonials front matter key.
The <li> element wraps each array item in our layout file, containing the HTML structure for each testimonial's content. To define an Array Item Editable Region, let's add the data-editable HTML attribute to the <li> DOM element. The value of data-editable HTML attribute should be array-item.
Where should the Array and Array Item Editable Regions go?
We recommend placing the Array Editable Region attribute or web component on the element that wraps your array templating, and the Array Item Editable Region attribute or web component on the first element inside each loop iteration. This way, Array and Array Item flank the templating for looping over your array.
Other HTML elements can sit between the Array and Array Item Editable Regions, but another Editable Region cannot. CloudCannon matches each Array Item Editable Region to its nearest parent Editable Region, and shows an error if that parent is not an Array Editable Region.
If we also want to visually edit the text and images inside each array item, we can define three Text Editable Regions A designated area within a webpage where Organization Members can modify text content directly through CloudCannon's visual editing interface. These regions allow inline text editing without requiring knowledge of HTML or Markdown. A designated area within a webpage where Organization Members can change an image in CloudCannon's Visual Editor. Image Editable Regions allow you to upload images from your local storage, select existing images from your repository or DAM, and manage image details like title or alt text.Text Editable Region
Image Editable Region
Here's what our layout file should look like:
---
const { testimonials } = Astro.props.frontmatter;
---
<ul data-editable="array" data-prop="testimonials">
{
testimonials.map((testimonial) => (
<li data-editable="array-item">
{testimonial.image && (
<img
data-editable="image"
data-prop-src="image"
data-prop-alt="image_alt"
src={testimonial.image}
alt={testimonial.image_alt}
/>
)}
<h4 data-editable="text" data-prop="name">{testimonial.name}</h4>
<p data-editable="text" data-prop="job_title">{testimonial.job_title}</p>
<p data-editable="text" data-prop="quote">{testimonial.quote}</p>
</li>
))
}
</ul>The data-editable attribute defines what kind of data this element contains, and the data-prop attribute defines the path to the data we want to edit. In this case, we want an Array Editable Region, so the value of data-editable is array, and we want to edit the testimonials structured data key in the file front matter.
This <img> element contains data-editable="image", data-prop-src="image", and data-prop-alt="image_alt" to define an Image Editable Region.
This <h4> element contains data-editable="text" and data-prop="name" to define a Text Editable Region.
This <p> element contains data-editable="text" and data-prop="job_title" to define a Text Editable Region.
This <p> element contains data-editable="text" and data-prop="quote" to define a Text Editable Region.
Once we save and rebuild our Site, CloudCannon will show a yellow Editable Regions box around each array item on the Testimonials page, and around each image and text field.

When you hover over an array item, CloudCannon will show a small toolbar in the top right of the array item, containing an edit icon and a drag handle icon. Clicking the edit icon will open a Data Panel containing your array item fields. Clicking the drag handle icon will open the Context Menu, with options to add, duplicate, move, and delete the array item, while clicking and holding the drag handle icon allows you to visually move an array item to any position in the array. For a vertical array, the move options are Move up and Move down, and for a horizontal array they are Move left and Move right.
When your team adds a new testimonial in the Visual Editor, CloudCannon copies the markup of an existing array item to display it. If your team deletes every testimonial, there is no array item left to copy, so adding a new one will show a red Error Card headed Failed to render array editable region. To avoid this, we can add a <template> element inside our Array Editable Region, containing the markup CloudCannon should use for every new array item.
Here's what our layout file looks like with a <template> element:
<ul data-editable="array" data-prop="testimonials">
<template>
<li data-editable="array-item">
<h4 data-editable="text" data-prop="name"></h4>
<p data-editable="text" data-prop="job_title"></p>
<p data-editable="text" data-prop="quote"></p>
</li>
</template>
{
testimonials.map((testimonial) => (
<li data-editable="array-item">
<h4 data-editable="text" data-prop="name">{testimonial.name}</h4>
<p data-editable="text" data-prop="job_title">{testimonial.job_title}</p>
<p data-editable="text" data-prop="quote">{testimonial.quote}</p>
</li>
))
}
</ul>The <template> element contains the markup for one array item. CloudCannon uses it to display any new array item until your Site rebuilds.
For more information about the options CloudCannon uses to render new array items, please read our documentation on configuring Array Editable Regions.
Common errors#
If you accidentally misconfigure your Editable Regions, CloudCannon will replace them in the Visual Editor with a red Error Card headed Failed to render array editable, Failed to render array editable region when it cannot render a new array item, or Failed to render array item for a misconfigured Array Item Editable Region, followed by a message describing the problem.

Here are a few common errors you might encounter with Array Editable Regions:
- You did not define the
data-propHTML attribute. - The value at the
data-proppath is not an array (e.g., it is a string, a number, or an object, or no value exists at that path). - You have one or more orphaned Array Item Editable Regions whose nearest parent Editable Region is not an Array Editable Region.
- CloudCannon cannot render a new array item, because your array is empty and your Array Editable Region has no
<template>element.
In the next step of this guide, we'll cover how to define Editable Regions for your components.