Skip to content

Kirby 4.4.1

Field methods

With field methods, you convert, validate, inspect or manipulate the content of your fields, for example, transform the field value to uppercase, convert it to another format or get a collection of pages from a list of URIs.

Examples

To give you an idea of what you can do with field methods, here are a few examples:

Echo a date field in a special format

<?= $page->createdAt()->toDate('Y-m-d') ?>

Check if a field exists

<?php if ($page->someField()->exists()): ?>
<!-- do something -->
<?php endif ?>

Check if the field value is true or false

<?php if ($page->myToggleField()->isTrue()): ?>
Yes, is true
<?php endif ?>

Return a fallback value if the field is empty

<?= $page->description()->or('This is my alternative description') ?>