Skip to content

Kirby 4.5.0

$field->toObject()

Parse yaml data and convert it to a content object

$field->toObject(): Kirby\Content\Content

Return type

Kirby\Content\Content

Example

This field method is intended for converting an object field to a content object.

<?php if ($contact = $page->contact()->toObject()): ?>
<dl>
  <dt><?= Str::ucfirst($contact->photo()->key()) ?></dt>
  <dd><?= $contact->photo()?->toFile()->crop(200) ?></dd>
  <dt><?= Str::ucfirst($contact->name()->key()) ?></dt>
  <dd><?= $contact->name() ?></dd>
  <dt><?= Str::ucfirst($contact->email()->key()) ?></dt>
  <dd><?= $contact->email() ?></dd>
  <dt><?= Str::ucfirst($contact->phone()->key()) ?></dt>
  <dd><?= $contact->phone() ?></dd>
</dl>
<?php endif ?>