I’m working on a director blueprint in Kirby 4 and running into trouble with a pages field that should list all “Works” tagged with a specific director.
Here’s the field in my blueprint:
listedPages:
headline: Works directed by {{ page.title }}
type: pages
help: Shows all Work pages that have this director assigned.
query: site.find("works").children.published.filterBy("director", "*=", page.id)
search: true
sortBy: title asc
create: false
This worked well before upgrading to Kirby 4, when page.id (like directors/matt-eastwood) was saved in the content files. But since upgrading, new Work pages store the director field like this:
Director: page://gjfOfkawCrvLxewA
So now, old projects match via page.id, and new ones use the uuid. That means filterBy('director', '*=', page.id) only shows the old ones — and page.uuid only shows the new ones.
Is there a way to write the query: in the blueprint to match either page.id or page.uuid?
I tried various combinations (e.g. arrays, logical OR, inline filters), but it looks like filterBy only allows one value, and query: doesn’t support full logic or callbacks.
Has anyone found a clean way to support both ID- and UUID-based references in blueprint queries?
Thanks in advance!
You can use not in with an array containing id and uuid
Thanks, can you please let me know how I would action that.
I tried both in which rendered no pages and also not in which rendered all of the work pages.
It still does not render only the pages with matching id and uuid
Could you please post the code you tried?
Both of these,
- first showing all work pages
- second showing no work pages
listedPages:
headline: Works directed by {{ page.title }}
type: pages
help: Shows all Work pages that have this director assigned.
query: site.find("works").children.published.filterBy("director", "not in", [page.id, page.uuid])
search: true
sortBy: title asc
create: false
listedPages:
headline: Works directed by {{ page.title }}
type: pages
help: Shows all Work pages that have this director assigned.
query: site.find("works").children.published.filterBy("director", "in", [page.id, page.uuid])
search: true
sortBy: title asc
create: false
Ah, ok, sorry. Yes, filterBy() won’t work here, because the data is stored in yaml format.
You need a custom director page model here.
/site/models/director.php
class DirectorPage extends Page
{
public function getWorks()
{
return page('works')->children()->filter(fn($work) => $work->director()->toPages()->has($this));
}
}
then in your blueprint:
query: page.getWorks()
Perfecto, thank you very much!