How to filter images via tags?


Maybe I’ve looked in the wrong places. So give me directions, please.

I’ve got a gallery-page. I’ve set up a tags-field in my files/default.yml:

  label: Tags
  type: tags
	- Humans
	- Cats
	- Dogs

This is working fine. I can see the tags in the TXT-Sidecars to the image-files.

I want to filter my images by those tags, if posslible without Js.

The only things I’ve found are about blog-posts. :frowning: My skills are growing, but maybe not good enought. Is there a cookbook, that I’ve missed?

Thank you in advance!


You can do it in the same way that you would filter page you render in a page, via parameters.

Let’s say you define your images in your controller or template:

$images = $page->images();

if ($tag = param('tag')) {
  $images = $images->filterBy('tags', $tag, ',');

The tag links would contain the parameter.

so the only difference between filtering pages and filtering files is the collection to which you apply the filter.