Skip to content

Kirby 4.4.1

$field->or()

Provides a fallback if the field value is empty

$field->or(mixed $fallback = null)

Parameters

Name Type Default
$fallback mixed null

Return type

Examples

Replace an empty field with another field

<meta name="description" content="<?= $page->description()->or($site->description()) ?>">

Replace an empty field with a fixed string

<meta name="description" content="<?= $page->description()->or('Default description') ?>">

Replace an empty field with null

<img <?= Html::attr(['width' => $file->displayWidth()->or(null)]) ?>>