Object
Structured object input, which stores properties as YAML.
The object field allows to create data objects. This is handy for more complex settings, isolated entities or nested data.
A typical example would be contact data for an author in a blog article, multiple layout settings for images in your template, custom settings for a theme, SEO configuration etc.
Example
Such an object will be stored in the content file like this:
If you need to store a list of multiple objects, take a look at the structure field.
Field properties
Name | Type | Default | Description |
---|---|---|---|
default | – | Set the default values for the object | |
disabled | bool |
– | If true , the field is no longer editable and will not be saved |
empty | – | The placeholder text if no information has been added yet | |
fields | array |
[] |
Fields setup for the object form. Works just like fields in regular forms. |
help | – | Optional help text below the field | |
label | – | The field label can be set as string or associative array with translations | |
required | bool |
– | If true , the field has to be filled in correctly to be saved. |
translate | bool |
true |
If false , the field will be disabled in non-default languages and cannot be translated. This is only relevant in multi-language setups. |
when | – | Conditions when the field will be shown (since 3.1.0) | |
width | string |
1/1 |
The width of the field in the field grid. Available widths: 1/1 , 1/2 , 1/3 , 1/4 , 2/3 , 3/4
|
Fields
You can define any number of fields and use the same field types listed:
Each field value is stored like in a normal Kirby content file. This means that all field types are supported, however all of their values are converted to strings. For most fields there is no difference, but structured fields will not be nested inside the same YAML data structure. This ensures broad compatibility.
Default values
You can set default values for an object field which will prepopulate the field when a new page is created.
How to use in templates/snippets
To access a object field in your templates, you can use the toObject()
method.
Let's say we wanted to render the contact
data from above in a template:
If you nest object fields inside another object field, block field or structure field, you have to call the toObject()
method on the nested fields as well and then access the nested object properties like above.