Issue with fetching cover image thumbnails from children pages

Hello everyone,

I got an issue with displaying “cover” thumbnails from single projects, I have a projects.yml blueprint containing overview of single projects (project.yml):

....  
  drafts:
    extends: sections/projects
    headline: Entwurf
    status: draft

  unlisted:
    extends: sections/projects
    headline: Vorschau
    status: unlisted

  listed:
    extends: sections/projects
    headline: Veröffentlicht
    status: listed
    size: medium
    layout: cards
...

section/projects.yml looks like this:

type: pages
headline: Projekte
parent: kirby.page("projekte")
info: "{{ page.published }}"
template: project
empty: Keine Projekte
sortBy: date desc
image:
query: page.cover
cover: true
ratio: 3/2

project.yml is blueprint with single project, it looks something like this with cover field:

....      
sidebar:
    width: 1/3
    sections:
      cover: fields/cover
....

fields/cover.yml looks like this:

type: files
headline: Cover
layout: cards
info: "{{ file.dimensions }}"
template: cover
min: 1
max: 1

As said, while in panel using project.yml cover field works great, I somehow can’t get thumbnails from project.yml to be shown in projects.yml page. What have I done wrong, I thought page.cover from section/projects.yml would fetch the cover field from project.yml and fields/cover? :slight_smile:

What you created is a section, not a field. How are to trying to fetch this cover image in your template?

I was using this in template

<?php foreach ($page->children()->listed() as $card): ?>
      <a href="<?= $card->url() ?>">
        <?php if ($cover = $card->images()->findBy("template", "cover")): ?>
      <img src="<?= $cover->url() ?>">
      <?php endif ?>
   <?php endforeach ?>

edit:
If there is a more elegant solution, I’d gladly accept it :smiley:

That code should actually work, unless the template information is for some reason missing from the file metadata (because you added the template later…).

Perfectly fine.

If I were you, I’d move the files section definition into /site/blueprints/sections instead of fields and change the reference accordingly, so as not to get confused in the future.

1 Like

Thank you for the suggestion of putting it in sections!

I’ve solved my problem above - the file blueprint was missing. Now everything works fine, my mistake - sorry.