In the pages section, the image property is set to use this field as cover image.
test_pages:
headline: Test Pages
type: pages
status: published
layout: cards
image:
query: page.page_icon.toFile
If the section includes the page type referenced by the files field (templates array includes files) than the images are displayed but if the files page type is not in the templates array only the default icon is displayed for all the pages.
Is this a bug or a limitation of the query references? Is this documented somewhere I didn’t catch?
Thanks!
Minimal working example starting from the starterkit:
Update site.yml at the bottom so both types can be created:
pages:
type: pages
create:
- default
- files
- test
templates:
- about
- home
- default
- files
- test
Create a files type page, upload some images and publish the page.
Create a test type page, select one image from the picker and publish the page.
Update site.yml, create a new files section where both page types are supported:
- width: 1/1
sections:
test_pages:
headline: Test Pages
type: pages
status: published
layout: cards
image:
query: page.page_icon.toFile
templates:
- test
- files
Expected behavior: both pages are displayed, the test type is displayed with the selected image and the files one with the default icon.
Actual behavior: exactly this
Update site.yml and remove the -files type from the template list leaving only test type
templates:
- test
Expected behavior: only the test type page is displayed with the selected image as cover.
Actual behavior: only the test type page is displayed, but with the default icon
and updated the site.yml blueprint for the section:
image:
query: page.displayIcon
Unfortunately the bug stayed. If I leave the page type in the templates list which contains the files they are displayed but if I remove it (which is the intention) no image is displayed for the other page types either.
Good point, I updated the function. The problem unfortunately stayed. Just by adding / removing one line from the templates array (the blueprint type containing the images) in the files section, I can switch between displaying the default images or the ones selected in the field.
Ok, now I understand the problem. That’s indeed really weird and seems to be a bug. I first thought it might be related to the page name files, but that doesn’t seem to be the case. Thanks for providing the Starterkit.
I did some debugging, tracing back the site/sections/(:any) API call all the way to the image function call in kirby/src/Panel/Model.php#L114 ($model->image() | Kirby CMS).
Here a protected imageSource function is called with the same parameter (page.page_icon.toFile) in both cases but returns a Kirby\Cms\File Object when the files blueprint type is part of the section and null if it’s not.