Skip to content

Kirby 4.4.1

$field->toBool()

Converts the field value into a proper boolean

$field->toBool(bool $default = false): bool

Parameters

Name Type Default Description
$default bool false Default value if the field is empty

Return type

bool

Aliases

You can use the following aliases for this field method in your template:

  • $field->bool(…)

Examples

Basic usage

<?php if ($page->hasHeader()->toBool()): ?>
<header>
  <!-- Your code here -->
</header>
<?php endif ?>

With default

<?php if ($page->hideHeader()->toBool(true)): ?>
<header>
  <!-- Your code here; printed even when the field is empty -->
</header>
<?php endif ?>