Skip to content

Kirby 3.7.5

$site->file()

Returns a specific file by filename or the first one

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

Parameters

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

Return type

Kirby\Cms\File|null

Parent class

Kirby\Cms\Site

Example

Fetching the first file

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

Fetching a specific file

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