Hi, I’m wondering if it’s possible to select images from another page?
I have Starterkit installed, which I’ve added a Gallery page to. Ideally I’d like to be able to populate the Photography > Album pages by selecting images from the Gallery page.
From having a browse on the forum, and looking at the documentation it seems I may be able to do this using a query in the blueprint. However, nothing I’ve tried seems to work.
Update: I’ve also tried using a page model for this.
site/models/album.php:
class AlbumPage extends Page
{
public function cover()
{
return $this->content()->get('cover')->toFile() ?? $this->image();
}
public function getAllImages()
{
return $this->images()->add($site->find('gallery')->images());
}
}
album.yml Blueprint:
title: Album
icon: 🖼
status:
draft: true
listed: true
columns:
- width: 1/3
fields:
cover: fields/cover
headline:
type: text
placeholder: "{{ page.title }}"
help: Leave empty to use the title as headline
subheadline:
type: text
text:
type: writer
tags: true
- width: 2/3
sections:
images:
type: files
layout: cards
size: medium
template: gallery-image
info: "{{ file.dimensions }}"
image:
ratio: 5/4
cover: true
options: query
query: page.getAllImages
uploads:
parent: site.find('gallery')
template: gallery-image
No luck with this either unfortunately.
Also, forgot to say I’m using Kirby 3.7.0.2 running on PHP 8.1.6
Thanks, I was already looking at that, and seem to have sussed it out.
Not sure if this will help anyone else in the future, but I’ve updated the file controllers/album.php to the below, and all seems to be working as expected.