Reference

Guide

$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 Description
$filename string null
$in string 'files'

Return type

Kirby\Cms\File|null

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 ?>

Source code

kirby/src/Cms/HasFiles.php#L88