Several images are not visible on the templates page

Several images are not visible on the templates page(album.php).
Is there something wrong with my code?

templates/album.php

<?php if ($page->spreadimagestype() == 'onebtn'): ?>
        <?php foreach ($page->spreadimages()->toFiles() as $spreadimages): ?>
      <figure class="single-image-box">
          <img class="lazy" src="<?= $spreadimages->resize(null, 100)->url() ?>" data-src="<?= $spreadimages->resize(null, 1024)->url() ?>">
        <a class="single-isbn" href="<?= $page->isbnurl() ?>" target="_blank">ISBN <?= $page->isbn() ?></a>
      </figure>
     <?php endforeach ?>
    <?php endif ?>

blueprints/pages/album.yml

tabs:
  onepage:
    label: μ„€λͺ… Description
    icon: text
    columns:
      - width: 1/1
        fields:
          spreadimagestype:
            type: radio
            default: onebtn
            options:
              onebtn: Show
              twobtn: Hide
          spreadimages:
            type: files
            layout: cards
            template: image
            uploads: false
            info: "{{ file.dimensions }}"
            image:
              ratio: 5/4
              cover: true

models/album.php

<?php
class AlbumPage extends Page
{
    public function cover()
    {
        return $this->content()->get('cover')->toFile() ?? $this->image();
    }

    public function spreadimages()
    {
        return $this->content()->get('spreadimages')->toFile() ?? $this->image();
    }
}

This returns a single file object if it exists.

This calls the method defined in the model, and then tries to call the toFiles() method on it. This doesn’t make sense.

What’s the purpose of the model if the spreadimages field is supposed to contain multiple images? Better remove it.

1 Like