Structure
Structured data input, which stores data in a field as YAML.
The structure field makes it possible to add multiple complex entries to a field, which will be stored as YAML. A typical use case would be a list of addresses, team members or a restaurant menu.
Example
Such a structure will be stored in the content file like this:
Field properties
Name | Type | Default | Description |
---|---|---|---|
columns | array |
[] |
Optional columns definition to only show selected fields in the structure table. |
default | array |
– | Set the default rows for the structure |
disabled | bool |
– | If true , the field is no longer editable and will not be saved |
duplicate | bool |
true |
Toggles duplicating rows for the structure |
empty | – | The placeholder text if no items have been added yet | |
fields * | array |
– | Fields setup for the structure 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 | |
limit | int |
– | The number of entries that will be displayed on a single page. Afterwards pagination kicks in. |
max | int |
– | Maximum allowed entries in the structure. Afterwards the "Add" button will be switched off. |
min | int |
– | Minimum required entries in the structure |
prepend | bool |
– | Toggles adding to the top or bottom of the list |
required | bool |
– | If true , the field has to be filled in correctly to be saved. |
sortBy | string |
– | Sorts the entries by the given field and order (i.e. title desc ) Drag & drop is disabled in this case |
sortable | bool |
– | Toggles drag & drop sorting |
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:
Default values
You can set default values for structure fields which will prepopulate the field:
Table columns
You can define the columns that are shown in the table. This is especially useful if you have a lot of fields in your structure and you don't want to show them all on first sight, but still keep them editable. Columns can also change the text alignment, set a custom width and define a before and after text that will be prepended or appended to the value.
Option | Value | Description |
---|---|---|
width |
1/2 , 1/3 , 1/4 , 2/3 , 3/4 (any fraction since v3.2.0) |
Set width of column |
align |
left , center , right |
Set text alignment |
before |
string |
Set text to prepend value |
after |
string |
Set text to append value |
mobile |
true |
Set visible in mobile view (since v3.6.0) |
Example
Structure columns can be set to any fraction and will be automatically calculated into the right width.
You can also define columns without additional options if you want to use the defaults. You can still combine this with options for other columns:
Hide toggle field text in preview
When using toggle fields within structures, displaying the field's text in the preview can sometimes look cluttered. You can hide the text with the text
option in the columns' definition.
Set columns to visible on mobile
The mobile
option keeps cells in responsive views. If none of the columns are set to mobile
, only the first column will be visible on mobile.
Preview of fields in the table
The structure field tries to create the best possible preview for the field in its table view. If you are using fields provided by a plugin in the structure field, the preview of these can be customized with a field preview extension.
How to use in templates/snippets
To access a structure field in your templates, you can use the yaml()
and toStructure()
methods.
Let's say we wanted to render the holidays
structure field example from above in a template:
If you nest structure fields inside a structure field, you have to call the toStructure()
method on the nested fields as well and then loop through the nested items like above.