Object Field
The Object field type allows users to create and manage nested objects within the CMS entry form. It provides a structured way to group related fields together.
User Interface
Editor
The Object field type has two different UI modes, depending on the configuration. You can have conditional subfields using either the fields option or the types option.
- With the
fieldsoption: A group of subfield editors is shown within a collapsible section. Ifrequiredis set tofalse, a checkbox to add or remove the object is displayed. - With the
typesoption: A type selector is shown, along with the corresponding subfield editors for the selected type. This configuration is called a variable type object. It’s useful for creating flexible content structures like page builders.
Preview
A read-only view of the object’s content, displaying the values of its nested fields in a structured format.
Data Type
An object containing nested fields as defined in the configuration.
If the required option is set to false and subfields are not added, the value will be null.
Data Validation
- If the
requiredoption is set totrue, the object must not benull(i.e., a type must be selected if using variable types).
Options
In addition to the common field options, the Object field supports the following options:
Required Options
widget
- Type:
string - Default:
string
Must be set to object to use the Object field type.
fields
- Type:
arrayof field definitions
Either fields or types must be provided. You cannot use both options simultaneously.
types
- Type:
arrayof variable type definitions
Either fields or types must be provided. You cannot use both options simultaneously.
Each type definition is an object with the following properties:
name(string, required): The unique identifier for the type.label(string, required): The display label for the type.widget(string, optional): The field type for this type. It must beobjectif not omitted. Other field types are invalid.fields(array of field definitions, optional): The subfields for this type.
Optional Options
default
- Type:
object - Default:
{}
The default value for the object field.
collapsed
- Type:
booleanorauto - Default:
false
Whether the object field is initially collapsed in the UI. If set to auto, the UI is collapsed if the object has any filled subfields and expanded if all the subfields are empty.
summary
- Type:
string - Default:
""
A string template used to generate a summary of the object’s content when it is collapsed in the UI. The template can include placeholders for subfield values using the syntax {{fieldName}}. String transformations can be applied in this option.
typeKey
- Type:
string - Default:
"type"
The key used to store the selected type name in a variable type object. The default key is type.
You cannot use a key that conflicts with any of the subfield names defined in the object.
TIP
Unlike most of other config options, typeKey is camelCased.
Examples
Standard Object
The following example defines an Object field named author with two subfields: name (a string) and bio (a text area).
- name: author
label: Author
widget: object
fields:
- name: name
label: Name
widget: string
- name: bio
label: Biography
widget: text[[fields]]
name = "author"
label = "Author"
widget = "object"
[[fields.fields]]
name = "name"
label = "Name"
widget = "string"
[[fields.fields]]
name = "bio"
label = "Biography"
widget = "text"{
"name": "author",
"label": "Author",
"widget": "object",
"fields": [
{
"name": "name",
"label": "Name",
"widget": "string"
},
{
"name": "bio",
"label": "Biography",
"widget": "text"
}
]
}{
name: "author",
label: "Author",
widget: "object",
fields: [
{
name: "name",
label: "Name",
widget: "string",
},
{
name: "bio",
label: "Biography",
widget: "text",
},
],
},Output example:
author:
name: Jane Doe
bio: Jane Doe is a writer and editor with over 10 years of experience.[author]
name = "Jane Doe"
bio = "Jane Doe is a writer and editor with over 10 years of experience."{
"author": {
"name": "Jane Doe",
"bio": "Jane Doe is a writer and editor with over 10 years of experience."
}
}Nested Object
An object can contain another object as a subfield. The following example defines an Object field named book with a nested Object field named publisher.
- name: book
label: Book
widget: object
fields:
- name: title
label: Title
widget: string
- name: publisher
label: Publisher
widget: object
fields:
- name: name
label: Name
widget: string
- name: address
label: Address
widget: text[[fields]]
name = "book"
label = "Book"
widget = "object"
[[fields.fields]]
name = "title"
label = "Title"
widget = "string"
[[fields.fields]]
name = "publisher"
label = "Publisher"
widget = "object"
[[fields.fields.fields]]
name = "name"
label = "Name"
widget = "string"
[[fields.fields.fields]]
name = "address"
label = "Address"
widget = "text"{
"name": "book",
"label": "Book",
"widget": "object",
"fields": [
{
"name": "title",
"label": "Title",
"widget": "string"
},
{
"name": "publisher",
"label": "Publisher",
"widget": "object",
"fields": [
{
"name": "name",
"label": "Name",
"widget": "string"
},
{
"name": "address",
"label": "Address",
"widget": "text"
}
]
}
]
}{
name: "book",
label: "Book",
widget: "object",
fields: [
{
name: "title",
label: "Title",
widget: "string",
},
{
name: "publisher",
label: "Publisher",
widget: "object",
fields: [
{
name: "name",
label: "Name",
widget: "string",
},
{
name: "address",
label: "Address",
widget: "text",
},
],
},
],
},Output example:
book:
title: The Great Gatsby
publisher:
name: Scribner
address: '123 Publisher St, New York, NY'[book]
title = "The Great Gatsby"
[book.publisher]
name = "Scribner"
address = "123 Publisher St, New York, NY"{
"book": {
"title": "The Great Gatsby",
"publisher": {
"name": "Scribner",
"address": "123 Publisher St, New York, NY"
}
}
}Variable Type
The following example defines a variable type Object field named contentBlock with three types: textBlock, imageBlock, and placeholderBlock. Note that the placeholderBlock type does not have any subfields but is still a valid type.
- name: contentBlock
label: Content Block
widget: object
types:
- name: textBlock
label: Text Block
fields:
- name: text
label: Text
widget: text
- name: imageBlock
label: Image Block
fields:
- name: image
label: Image
widget: image
- name: placeholderBlock
label: Placeholder Block[[fields]]
name = "contentBlock"
label = "Content Block"
widget = "object"
[[fields.types]]
name = "textBlock"
label = "Text Block"
[[fields.types.fields]]
name = "text"
label = "Text"
widget = "text"
[[fields.types]]
name = "imageBlock"
label = "Image Block"
[[fields.types.fields]]
name = "image"
label = "Image"
widget = "image"
[[fields.types]]
name = "placeholderBlock"
label = "Placeholder Block"{
"name": "contentBlock",
"label": "Content Block",
"widget": "object",
"types": [
{
"name": "textBlock",
"label": "Text Block",
"fields": [
{
"name": "text",
"label": "Text",
"widget": "text"
}
]
},
{
"name": "imageBlock",
"label": "Image Block",
"fields": [
{
"name": "image",
"label": "Image",
"widget": "image"
}
]
}
{
"name": "placeholderBlock",
"label": "Placeholder Block"
}
]
}{
name: "contentBlock",
label: "Content Block",
widget: "object",
types: [
{
name: "textBlock",
label: "Text Block",
fields: [
{
name: "text",
label: "Text",
widget: "text",
},
],
},
{
name: "imageBlock",
label: "Image Block",
fields: [
{
name: "image",
label: "Image",
widget: "image",
},
],
},
{
name: "placeholderBlock",
label: "Placeholder Block",
},
],
},The output will vary based on the selected type, which is indicated by the type key (customizable via the typeKey option). If no fields are defined for a type, the object will only contain the type key, as shown in the placeholderBlock example below.
Output example for a textBlock type:
contentBlock:
type: textBlock
text: 'This is a sample text block.'[contentBlock]
type = "textBlock"
text = "This is a sample text block."{
"contentBlock": {
"type": "textBlock",
"text": "This is a sample text block."
}
}Output example for an imageBlock type:
contentBlock:
type: imageBlock
image: /images/sample.jpg[contentBlock]
type = "imageBlock"
image = "/images/sample.jpg"{
"contentBlock": {
"type": "imageBlock",
"image": "/images/sample.jpg"
}
}Output example for a placeholderBlock type:
contentBlock:
type: placeholderBlock[contentBlock]
type = "placeholderBlock"{
"contentBlock": {
"type": "placeholderBlock"
}
}