Problem with downloading images in a loop

Why this code doesn’t work

<?php foreach ($page->Containerb()->toFile() as $imgB) : ?>
     <a href="<?= $imgB->url() ?>" data-fancybox="container-B"> </a>
<?php endforeach ?>

Containerb contains this:


 - file://EtfNtPnmsVvuBzOs
 - file://YTMtpSGNvXODy1xl
 - file://4nGDM3MVEYvJeP4e


It gets this error: call to a member function url() on null

And this code is already working
<img src="<?= $page->Containerb()->toFile()->url() ?>">.

This returns either null (if the image doesn’t exist) or a file object. You cannot loop through a file object.

You need to convert multiple values in a files field with toFile**s**() to get a files collection. See docs: Files | Kirby CMS

Well, that’s a stupid typo, instead of toFile() I should have entered toFiles()

Thank you for your answer : )