Skip to content

Commit

Permalink
Explain YAML storage in structure/object field ref
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbestle committed Nov 15, 2023
1 parent c33f4cd commit 84d28bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Guide: blueprints/fields

Text:

The new object field allows to create data objects. This is handy for more complex settings, isolated entities or nested data.
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.

Expand Down Expand Up @@ -48,6 +48,8 @@ contact:
phone: 1234 5678
```

If you need to store a list of multiple objects, take a look at the (link: docs/reference/panel/fields/structure text: structure field).

## Field properties

(field-options: object)
Expand All @@ -58,6 +60,10 @@ You can define any number of fields and use the same (link: docs/reference/panel

(reference: panel/fields)

<info>
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.
</info>

## Default values

You can set default values for an object field which will prepopulate the field when a new page is created.
Expand Down Expand Up @@ -105,4 +111,3 @@ Let's say we wanted to render the `contact` data from above in a template:
<info>
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.
</info>

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Title: Structure

Intro:

Structured data input, which stores data in a field as YAML.
Structured data input, which stores data as YAML.

----

Expand Down Expand Up @@ -55,6 +55,8 @@ addresses:
city: The capitol of the Bahamas
```

If you need to store a single object instead of a list of objects, take a look at the (link: docs/reference/panel/fields/object text: object field).

## Field properties

(field-options: structure)
Expand All @@ -65,6 +67,10 @@ You can define any number of fields and use the same (link: docs/reference/panel

(reference: panel/fields)

<info>
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 fields with structured data will *not* be nested inside the same YAML data structure. This ensures broad compatibility.
</info>

## Default values

You can set default values for structure fields which will prepopulate the field:
Expand Down Expand Up @@ -249,5 +255,3 @@ If you nest structure fields inside a structure field, you have to call the `toS
## More information

(link: docs/cookbook/content/structured-field-content text: Structured field content)


0 comments on commit 84d28bd

Please sign in to comment.