Image query: page.cover not working / only working with specific blueprint name?

Hi,

I just got started switching from working with Kirby 2 to Kirby 3. To practice, I started working on a small, simple portfolio site, but I’m running into a strange issue when trying to set up a »Projects« page.

Note: I’m basing most of my blueprints on the Kirby 3 Starterkit, because it comes with a lot of handy things.

The blueprint for my »Projects« page look like this:

title: Projects

icon: 📷

sections:
  projects:
    type: pages
    headline: Published Projects

    size: tiny
    info: "{{ page.images.count }} image(s)"
    layout: cards

    template: project

    empty: No projects yet

    image:
      query: page.cover
      cover: true
      ratio: 5/4

Notice how I am using the page.cover query from the Starterkit albums.yml blueprint.

The corresponding »Project« blueprint looks like this:

title: Project

icon: 🎆

status:
  draft: true
  listed: true

columns:
  - width: 2/3
    sections:
      images:
        type: files
        layout: cards
        template: image
        info: "{{ file.dimensions }}"
        image:
          ratio: 5/4
          cover: true
        min: 0
        size: small

  - width: 1/3
    fields:
      cover:
        type: files
        multiple: false
      headline:
        type: text
      description:
        type: textarea
      tags: true

Again, this is pretty much a copy of the Starterkit’s album.yml.

However, when I create a project page (as a subpage of »Projects«) a couple things from the blueprint fail to work. 1) The cover image is not being displayed (instead its just the icon defined in the blueprint) and 2) the empty text defined in the blueprint does not show up in the section (instead it just says »No pages yet«).


When there are no projects yet, the empty text should say »No projects yet«


An image is uploaded to the project + set to be this project’s cover…


…but it does not show up in the section of the project’s parent.

However, and this confuses me, when I set the template for the pages of »Projects« to album and rename project.yml into album.yml, the cover shows up just fine:

41

Can someone help me understand what is going on here and why renaming my blueprint to »album« instead of »project« fixes the cover issue?

Placeholder text not working is a bug that will be fixed in 3.0.3.

  1. problem: it will work if you do this:
    (took me a while to get what the problem was)
image:
  query: page.cover.toFile

The reason is, that cover doesn’t refer to a filename, but a page method called cover. The album page uses a page model with a cover method that returns the image selected in the cover if if it exists, or the first file. Your new page doesn’t have such a page model.

This is the model /site/models/album.php

<?php

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

Thanks :slight_smile: Just read up on page models, makes perfect sense :ok_hand: