Check if page has file type

How can I check whether a page contains a specific file type? In this case a pdf file.

<?php if($document = $project->files()->findBy('extension', 'pdf'); ?>
     <div class="download-btn">
         <a href="<?= $project->files()->findBy('extension', 'pdf')->url() ?>" target="_blank">Download</a>
<?php endif ?>

Unless there are no other types of documents:



if($page->files()->filterBy('extension', 'pdf')->count()) {
//do stuff

You can also create a custom page function that does this.

page::$methods['hasPDF'] = function($page) {
  return $page->files()->filterBy('extension', 'pdf')->count();
1 Like

Thanks for the help @texnixe!

You are welcome :slightly_smiling_face: