I’m trying to make make a full list of images that are in the /content.
This example for $site->images() seems to be doing exactly that, yet it doesn’t show anything.
Can anyone guess why that would be?
The $page->images() works fine everywhere, so I don’t think there’s anything particularly wrong with the images themselves or the structures around it.
The code I’m using is not different than the example, but just in case you can look at my images.php template at github.
I would appreciate any clue to solve this issue. Thanks!
$site->images() only fetches image files at the root of your content folder (uploaded to the “Site Options” area of the Panel).
You may need to loop over each page in $site->index(), then output the images for each of them. as far as I know, there is no way to directly fetch all images from a collection of pages.
In the latest Kirby update, $pages->files() was introduced, so you could use that for now. (It’s not documented yet, but it simply gets all files of a pages collection, so you can do $site->index()->files())
Maybe there should also be $pages->images(), or is there already a super straightforward way to filter all images from the collection returned by $pages->files()?
public function images() { return $this->files()->filterBy('type', 'image'); }
public function videos() { return $this->files()->filterBy('type', 'video'); }
public function documents() { return $this->files()->filterBy('type', 'document'); }
public function audio() { return $this->files()->filterBy('type', 'audio'); }
public function code() { return $this->files()->filterBy('type', 'code'); }
public function archives() { return $this->files()->filterBy('type', 'archive'); }