$page->file()
Returns a specific file by filename or the first one
$page->file(string|null $filename = null, string $in = 'files'): Kirby\Cms\File|null
Parameters
Name | Type | Default |
---|---|---|
$filename | string ornull |
null
|
$in | string |
'files'
|
Return types
Kirby\Cms\File
ornull
This method modifies the existing $page
object it is applied to and returns it again.
Parent class
Examples
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 ?>