Query images of page and all subpages in blueprint

panel

#1

I want to query all images of the page (page.images) and of its children (page.index.images). I can’t find a way to combine both queries into one.
This is to select a cover-image for the page in the panel.

I’ve tried it this way, but haven’t been successful:

fields:
  coverimage:
    type: files
    options: query
    query: page.index.prepend($page->id(), $page).images

I’m not sure if the approach and/or the syntax of the query is wrong.
Maybe someone knows a better way to query all images of a page and its children in one field.


#2

A page model would be the way to go. In your model, merge the images from the page with the images from the index.

You can the use the model method in your query.


#3

I am trying to implement it with a page model and got stuck again.

site/models/album.php

<?php
class ProjectPage extends Page {
  public function getAllImages() {
    return $this->images()->add($this->children()->images());
  }
}

site/models/album.yml

fields:
  coverimage:
    type: files
    options: query
    query: page.getAllImages
    multiple: false

The panel is displaying “The files query does not seem to be correct”.
If I’m changing the return value in the page model to $this->images(), the same message is displayed in the panel regardless.


#4

You can’t put the blueprint into site/models. That’s where the model goes, the blueprint still goes into site/blueprints/pages


#5

It’s actually in the blueprints folder. I just wrote it wrong in the post. -_-

I used “ProjectPage” as class name in the page model. It should be “AlbumPage” instead. I simply copied the example in the guide and didn’t thought about the class name. Next time I have to read the documentation more carefully.

Thanks for the help again. I really appreciate the support here.