Accessing file blueprint from subpages

I am trying to access image files on a page from it’s corresponding subpage but I am coming up with an error I can’t figure out

<?php foreach ($page->children()->listed() as $project): ?>
    <li>
        <div class="project-placeholder">
            <img class="" src="<?= $project->mobilethumbnail()->toFile()->url() ?>" alt="<?= $project->alt() ?>"
          srcset="<?= $project->mobilethumbnail()->toFile()->srcset([300, 800, 1024, 1400]) ?>" />
        </div>
    </li>
<?php endforeach ?>

Blueprint:

content:
  type: fields
  fields:
    mobilethumbnail:
      type: files
      max: 1
      label: Mobile Thumbnail Placeholder

Always use an if statement to make sure you have a file object before calling any of the class methods:


<?php foreach ($page->children()->listed() as $project): ?>
   <?php if ( $image = $project->mobilethumbnail()->toFile()) : ?>
    <li>
        <div class="project-placeholder">
            <img class="" src="<?= $image->url() ?>" alt="<?= $project->alt() ?>"
          srcset="<?= $image->srcset([300, 800, 1024, 1400]) ?>" />
        </div>
    </li>
    <?php endif ?>
<?php endforeach ?>

Sure you don’t want $image->alt() instead of $project->alt() for the alt attribute?