Set custom image for page cover

It seems like an easy topic, but what ever I tried I am not able to set a custom image for a page cover in the panel. Setting a custom icon is easy or getting the first image. But how can a set a specific image, let’s say like:

image:
query: “assets/images/my_custom_cover_image.jpg”

Hey and welcome to the forum

You have to return a file or asset object from your query, not just a path to a file.

So create a page model with a method like this:

 public function getAsset()
    {
        return Asset('assets/images/test.jpg');
    }

Then query:

image:
  query: page.getAsset()
1 Like

Thanks for the quick response. Unfortunatley I am kind of confused now. The documentation of the page model is dealing with the possibility to extend a page in order wo access custom functions in my templates. Not sure, if this is what I am looking for.

On my panel main site I have this:

My goal is to give “Schaukasten”, “QR Code Galerie”, etc. a custom image in the panel.

Following your advice I added a “schaukasten.php” to the models folder (site/models).

The code of the schaukasten.php currently looks like this:

<?php
class ProjectPage extends Page {
    public function getAsset()
        {
            return Asset('assets/images/background.png');
        }
    // all methods of the Page class are inherited and can be overridden here now.
  }

And the corresponding schaukasten.yml - blueprint like this:

title: Schaukasten

options:
  preview: false
  singleLanguage: true

image:
  query: page.getAsset()

sections:
    events:
        type: pages
        template: event
        layout: cards

Probably I mixed up somehing here.
And also constantly thinking, that there should be an easier way for setting a custom cover image…

You need to have this custom model method in the model of the pages in the stationen section (assuming here that Schaukasten, QR-Code Galerie and Dachgeschoss all use the same blueprint). The model must have the name of these children blueprints. So if schaukasten etc. use the schaukasten blueprint, your page model must be called SchaukastenPage, not ProjectPage.

1 Like