Reference

Guide

$files->find()

Find one or multiple elements by id

$files->find(string $keys = null): mixed

Parameters

Name Type Default Description
$keys string null

Return type

mixed

Example

Fetch a single file

if ($file = $page->files()->find('myfile.pdf')):
  echo $file->url();
endif;

Fetch multiple files

<ul>
  <?php foreach ($page->files()->find('document-a.pdf', 'document-b.pdf', 'document-c.pdf') as $file): ?>
  <li>
    <a href="<?= $file->url() ?>">
      <?= $file->filename()->html() ?>
    </a>
  </li>
  <?php endforeach ?>
</ul>

Finding a file in the sibling files collection

if ($file = $page->siblings()->files()->find('ocean/attention-sharks.jpg')):
  echo $file->url();
endif;

Finding a file in the complete index

if ($file = $site->index()->files()->find('photography/ocean/attention-sharks.jpg')):
  echo $file->url();
endif;

Inherited from

Kirby\Toolkit\Collection

Source code

kirby/src/Toolkit/Collection.php#L345