Just Googling adding images to pages in Kirby brings up lots of people asking the same questions and everyone a different answer.
I am totally confused about adding images to pages and the examples on YouTube etc all focus around galleries and not single images.
For example I’m setting up a page with a main cover image and 3 sub images, I want them all to be different file selectors in the blueprint so the client knows exactly what image they are choosing.
But I’m stuck about how to do this with images? In the blueprint have a field for cover image and upload that, then have separate fields for image one etc…
Then once you have set for example the cover image, how can this be accessed from another page on a news page for example where the cover is the child’s main image?
In Kirby there are several ways to upload images: files section, files field, textarea upload, blocks upload.
For your use case, you would probably have one upload section that shows all uploaded images, and files fields to select individual images out of the uploaded ones for the cover etc.
Whether or not the user can upload/select one or multiple images can be set through the min and max properties. You can find how to output images from a files field in the linked documentation, depending on whether the field has one or multiple images/files.
The documentation for images just references getting the first image or an image by name, but what if the client has uploaded an image into the list and needs to get it?
When you just upload files via a files section, you can assign a specific file blueprint to such a section and then filter all files of the page by this particular template:
This works and pulls the images into the correct places on the page template.
Two things I’m not sure of are:
The file blueprint template you mentioned above, I have added a file to blueprints > files > cover.yml as ‘template: cover’ is mentioned in your code, but this doesn’t seem to do anything? If you click the image is just comes up with the default files template and not a specific one.
As $image = $page->cover()->toFile(); now references cover on this page, how can this be accessed from other pages? For example the cover is the main image on the news article page and I want the the cover image to the main news post image on the overall news page.
In a files field, you cannot assign a template via the template property, that only works for files sections.
If you upload files through your files field, then you can set the file blueprint to assign to the uploaded file via the uploads property, as per the documentation
(It pays off to always have a closer look at the docs and to play around a bit with the different options).