Templating the Group field

The Group field is used to create a repeatable collection of fields.


Before Reading

This article assumes that you have saved the document object in a variable named document as shown in the Retrieve the document object page.

Example 1

Here is how to retrieve all the content within a Group field with the API ID of references. In this case, the Group field contains a Link field with the API ID of link and a Key Text field with the API ID of link_label.

Copy
const references = document.references.map(reference => {
  return {
    url: reference.link.url,
    label: reference.link_label
  }
})

Example 2

Here's another example that shows how to retrieve a group of images (e.g. a photo gallery) from a Group field with the API ID of photo_gallery. In this example, the Group field contains an Image field with the API ID of photo and a Key Text field with the ID of caption.

Copy
const photoGallery = document.photo_gallery.map(image_with_caption => {
  return {
    url: image_with_caption.photo.url,
    caption: image_with_caption.caption
  }
})