Skip to content

Kirby 5.0.4

$field->toFile()

Returns a file object from a filename in the field

$field->toFile(): Kirby\Cms\File|null

Return types

Kirby\Cms\Fileornull

This method modifies the existing $field object it is applied to and returns it again.

Examples

<?php if ($cover = $page->cover()->toFile()): ?>
<figure class="cover">
  <img src="<?= $cover->url() ?>" alt="<?= $cover->alt() ?>">
</figure>
<?php endif ?>