# Object

Structured object input, which stores properties as YAML.

****

- Read more: <https://getkirby.com/docs/guide/blueprints/fields>
- Source: <https://github.com/getkirby/kirby/tree/5.5.3/config/fields/object.php>

****

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.

<figure class="image"><a data-lightbox href="https://assets.getkirby.com/media/pages/docs/reference/panel/fields/object/0f49ba957d-1717846665/object.png?width=1416&amp;height=546&amp;enlarge=0"><img alt="" class="rounded" height="356" loading="lazy" sizes="auto" src="https://assets.getkirby.com/media/pages/docs/reference/panel/fields/object/0f49ba957d-1717846665/object.png?width=924&amp;height=356&amp;enlarge=0" srcset="https://assets.getkirby.com/media/pages/docs/reference/panel/fields/object/0f49ba957d-1717846665/object.png?width=462&amp;height=178&amp;enlarge=0 462w, https://assets.getkirby.com/media/pages/docs/reference/panel/fields/object/0f49ba957d-1717846665/object.png?width=690&amp;height=266&amp;enlarge=0 690w, https://assets.getkirby.com/media/pages/docs/reference/panel/fields/object/0f49ba957d-1717846665/object.png?width=924&amp;height=356&amp;enlarge=0 924w, https://assets.getkirby.com/media/pages/docs/reference/panel/fields/object/0f49ba957d-1717846665/object.png?width=1380&amp;height=532&amp;enlarge=0 1380w, https://assets.getkirby.com/media/pages/docs/reference/panel/fields/object/0f49ba957d-1717846665/object.png?width=1416&amp;height=546&amp;enlarge=0 1848w" width="924"></a></figure>

## Example

```yaml
fields:
  contact:
    type: object
    fields:
      photo:
        type: files
      name:
        type: text
      email:
        type: email
      phone:
        type: tel
```

Such an object will be stored in the content file like this:

```yaml
contact:
  photo:
    - file://hb38HvnQfm8HlQ6e
  name: Nandi Peters
  email: nandi@example.com
  phone: 1234 5678
```

If you need to store a list of multiple objects, take a look at the <a href="https://getkirby.com/docs/reference/panel/fields/structure">structure field</a>.

## Field properties



<div class="table">
	<table class="parameters">
		<thead>
			<tr>
				<th>Name</th>
				<th>Type</th>
				<th>Default</th>

								<th>Description</th>
							</tr>
		</thead>
		<tbody>
						<tr>
				<td>
					default				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Set the default values for the object</td>
							</tr>
						<tr>
				<td>
					disabled				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>If <code class="type type-bool">true</code>, the field is no longer editable and will not be saved</td>
							</tr>
						<tr>
				<td>
					empty				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>The placeholder text if no information has been added yet</td>
							</tr>
						<tr>
				<td>
					fields				</td>
				<td><code class="type type-array">array</code></td>

				<td data-label="Default:">
															<code>[ ]</code>
									</td>

								<td>Fields setup for the object form. Works just like fields in regular forms.</td>
							</tr>
						<tr>
				<td>
					help				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Optional help text below the field</td>
							</tr>
						<tr>
				<td>
					label				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>The field label can be set as string or associative array with translations</td>
							</tr>
						<tr>
				<td>
					required				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>If <code class="type type-bool">true</code>, the field has to be filled in correctly to be saved.</td>
							</tr>
						<tr>
				<td>
					translate				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>true</code>
									</td>

								<td>If <code class="type type-bool">false</code>, the field will be disabled in non-default languages and cannot be translated. This is only relevant in multi-language setups.</td>
							</tr>
						<tr>
				<td>
					when				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Conditions when the field will be shown (since 3.1.0)</td>
							</tr>
						<tr>
				<td>
					width				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>'1/1'</code>
									</td>

								<td>The width of the field in the field grid, e.g. <code class="type">1/1</code>, <code class="type">1/2</code>, <code class="type">1/3</code>, <code class="type">1/4</code>, <code class="type">2/3</code>, <code class="type">3/4</code></td>
							</tr>
					</tbody>
	</table>
</div>

## Fields

You can define any number of fields and use the same <a href="https://getkirby.com/docs/reference/panel/fields">field types listed</a>:

<nav class="auto-fill mb-12 text-sm" style="--min: 20rem; --gap: var(--spacing-1)">
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/blocks" style="text-decoration: none">
		<strong class="block">Blocks</strong>
		A visual editor for long-form text and modular pages	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/checkboxes" style="text-decoration: none">
		<strong class="block">Checkboxes</strong>
		A list of checkbox fields	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/color" style="text-decoration: none">
		<strong class="block">Color</strong>
		The color field supports multiple color notations, a color picker, pre-defined colors, custom color names, and transparency.	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/date" style="text-decoration: none">
		<strong class="block">Date</strong>
		A date picker field	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/email" style="text-decoration: none">
		<strong class="block">Email</strong>
		An email input field with validation	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/entries" style="text-decoration: none">
		<strong class="block">Entries</strong>
		The entries field allows you to create and manage multiple entries for the same field.	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/files" style="text-decoration: none">
		<strong class="block">Files</strong>
		A files select field that allows you to select one or more files out of a given set. A reference to this file is stored in the content file.	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/gap" style="text-decoration: none">
		<strong class="block">Gap</strong>
		Layout field to create gaps in the field grid.	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/headline" style="text-decoration: none">
		<strong class="block">Headline</strong>
		Creates a headline to group fields	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/hidden" style="text-decoration: none">
		<strong class="block">Hidden</strong>
		Creates a hidden field	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/info" style="text-decoration: none">
		<strong class="block">Info</strong>
		A plain HTML field for user instructions	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/layout" style="text-decoration: none">
		<strong class="block">Layout</strong>
		A visual editor for complex multi-column layouts	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/line" style="text-decoration: none">
		<strong class="block">Line</strong>
		Draws a horizontal line to separate fields	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/link" style="text-decoration: none">
		<strong class="block">Link</strong>
		Use the link field to create links to external URLs, internal pages, files, email addresses and telephone numbers. The link field is also used in the link dialogs of the writer and textarea fields.	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/list" style="text-decoration: none">
		<strong class="block">List</strong>
		A simple WYSIWYG editor field for ordered and unordered lists	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/multiselect" style="text-decoration: none">
		<strong class="block">Multiselect</strong>
		A select field that allows you to select multiple options	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/number" style="text-decoration: none">
		<strong class="block">Number</strong>
		A number input field with validation	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/object" style="text-decoration: none">
		<strong class="block">Object</strong>
		Structured object input, which stores properties as YAML.	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/pages" style="text-decoration: none">
		<strong class="block">Pages</strong>
		A pages select field that allows to select one or multiple related pages	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/radio" style="text-decoration: none">
		<strong class="block">Radio</strong>
		A list of radio buttons	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/range" style="text-decoration: none">
		<strong class="block">Range</strong>
		A handy slider	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/select" style="text-decoration: none">
		<strong class="block">Select</strong>
		A simple selectbox field	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/slug" style="text-decoration: none">
		<strong class="block">Slug</strong>
		A slug input field	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/stats" style="text-decoration: none">
		<strong class="block">Stats</strong>
		Show beautiful stats for your site or shop: revenues, orders, likes, views, etc.	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/structure" style="text-decoration: none">
		<strong class="block">Structure</strong>
		Structured data input, which stores data as YAML.	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/tags" style="text-decoration: none">
		<strong class="block">Tags</strong>
		An interactive tags input field with autocompletion	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/tel" style="text-decoration: none">
		<strong class="block">Tel</strong>
		A phone number input field	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/text" style="text-decoration: none">
		<strong class="block">Text</strong>
		A standard, single-line input field	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/textarea" style="text-decoration: none">
		<strong class="block">Textarea</strong>
		A textarea field, which auto-resizes and has built-in format buttons.	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/time" style="text-decoration: none">
		<strong class="block">Time</strong>
		A time picker field	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/toggle" style="text-decoration: none">
		<strong class="block">Toggle</strong>
		Yes/no or on/off toggle	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/toggles" style="text-decoration: none">
		<strong class="block">Toggles</strong>
		Toggle between different states	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/url" style="text-decoration: none">
		<strong class="block">Url</strong>
		A URL input field with validation	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/users" style="text-decoration: none">
		<strong class="block">Users</strong>
		A user select field that allows to select one or multiple users	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/panel/fields/writer" style="text-decoration: none">
		<strong class="block">Writer</strong>
		A simple WYSIWYG editor field for inline content with formats like bold, italic, etc.	</a>
	</nav>

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

```yaml
fields:
  contact:
    type: object
    default:
      name: Nandi Peters
      email: nandi@example.com
      phone: 1234 5678
    fields:
      photo:
        type: files
      name:
        type: text
      email:
        type: email
      phone:
        type: tel
```

## How to use in templates/snippets

To access a object field in your templates, you can use the [`toObject()`](/docs/reference/templates/field-methods/to-object) method.

Let's say we wanted to render the `contact` data from above in a template:

```php
<?php if ($contact = $page->contact()->toObject()): ?>
<dl>
  <dt>Photo</dt>
  <dd><?= $contact->photo()?->toFile()->crop(200) ?></dd>
  <dt>Name</dt>
  <dd><?= $contact->name() ?></dd>
  <dt>Email</dt>
  <dd><?= $contact->email() ?></dd>
  <dt>Phone</dt>
  <dd><?= $contact->phone() ?></dd>
</dl>
<?php endif ?>
```

<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>