Foreach loop not loading more than one image

Hello :slight_smile:
I’m having an issue where only one image seems to be rendered with a foreach loop. The loop renders the other information of the other children in the loop but only renders one of the images.

Here is the loop

      <?php foreach($page->children() as $issue): ?>
        <a<?php e($issue->isOpen(), ' class="active"') ?> href="<?= $issue->url() ?>">
        <?php if($image = $issue->cover()->toFile()): ?>
          <img src="<?= $image->url() ?>" alt="">
        <?php endif ?>
          <h2><?= $issue->title()->html() ?></h2>
          <div class="issue-info">
            <h3><?= $issue->Theme() ?></h3>
            <h3 style="text-align:right;"><?= $issue->published()->toDate('Y') ?></h3>
      <?php endforeach ?>

the problem can be seen here: Robida | Robida Magazine

Any help would be greatly appreciated as I can’t see anything wrong with the code or the content.


Well, you are only requesting one image here from a cover field?

Which images do you want to get instead?

There should be one image (cover) per issue. The foreach loop runs through all the issues which should load the details and cover for each issue. It succeeds in getting the details of each issue and the title, but only prints out the cover for the first issue. Does that make sense?

Ok, understand. But if no image is output, then there is probably none selected? Or the selected image was deleted from the field or renamed, so that $issue->cover()->toFile() returns null.

yes that’s logical, but in the panel there is an image uploaded to the cover field for each of the issues. So there should be an cover image returned for each issue.

The blueprint field for each issue’s cover is as such

        headline: Cover image
        type: files
        max: 1
        template: cover
        label: cover

Is there a way to see what Kirby does with the information in the panel?

Check your content files. And is this a field or a section, can’t tell from that blueprint snippet. If you can’t find the error, please post your complete blueprint. Thank you!