Skip to content

Kirby 3.8.4

$files->find()

Find one or multiple elements by id

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

Parameters

Name Type Default
$keys string null

Return type

mixed

Parent class

Kirby\Cms\Files inherited from Kirby\Toolkit\Collection

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>

Note that you have to pass the file path in relation to the given page if you try to find a specific file within a pages collection.

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;