Skip to content

Kirby 4.1.2

$page->file()

Returns a specific file by filename or the first one

$page->file(?string $filename = null, string $in = 'files'): Kirby\Cms\File|null

Parameters

Name Type Default
$filename string|null null
$in string 'files'

Return type

Kirby\Cms\File|null

Parent class

Kirby\Cms\Page

Example

Fetching the first file

<?php if($file = $page->file()): ?>
<a href="<?= $file->url() ?>">
  <?= html($file->filename()) ?>
</a>
<?php endif ?>

Fetching a specific file

<?php if($file = $page->file('myfile.pdf')): ?>
<a href="<?= $file->url() ?>">
  <?= html($file->filename()) ?>
</a>
<?php endif ?>