I have got the pagesdisplay plugin installed, and tested it with some of the example queries. All working great.
I am going with a page method, as I will probably need to use this elsewhere. I have this in my blueprint as my section:
primarySchools:
headline: Primary schools
type: pagesdisplay
query: site.currentUser
status: all
create: false
templates: school
image: false
And this in site/plugins/page-methods/index.php
:
<?php
Kirby::plugin('mhd/page-methods', [
'pageMethods' => [
'currentUser' => function () {
return $this->children()->filter(function($child) {
return $child->mentor()->toUser() === kirby()->user();
});
}
]
]);
But am getting the following error:
The section “primarySchools” could not be loaded: Query result must be of type “Kirby\Cms\Pages”, “Kirby\Cms\Field” given
The pages I am filtering are all top level, and I need to do an additional filter on them as well (site.index.filterBy('schoolType', '==', 'primary')
, which I have tried and works well), but it would be good to get the user filtering working.
This is in a user-specific blueprint using the method here: Different site blueprint depending on user - if that makes any difference, but I don’t think it would
=======================
UPDATE
I have tried this as my query (the first part works great):
query: site.index.filterBy('schoolType', '==', 'primary').currentUser
And this as the method:
Kirby::plugin('mhd/page-methods', [
'pageMethods' => [
'currentUser' => function () {
return $this->mentor() == kirby()->user();
}
]
]);
But then get this error:
**The section "primarySchools" could not be loaded:** Query result must be of type "Kirby\Cms\Pages", "null" given