Get all images with Tag from URL

Hello there,

after working with kirby the first hours i am still impressed… :slight_smile:
Now i have the question:
We have several pages inside the Kirby Installation, inside the pages are images placed, with blueprint i added “tags” to the images.
Is there a chance to filter all images from Kirby with the tag i receive from the URL with “imagetag:XYZ”?

So i can setup a gallery page where dynamically the images with the tag i choose are placed.

Is there also a chance to get all tags in Kirby i am using? Like all active tags?

Thank you all!

1 Like

Yes, you can do this in the same way as you filter pages, only using a files collection instead of a pages collection.

More details in this cookbook recipe: https://getkirby.com/docs/cookbook/filtering

Yes, you can use the pluck() method to fetch all tags used in your file meta data: $files->pluck() | Kirby CMS

1 Like

Do you want a gallery per page, or a gallery for the entire site that shows all images (which are in different pages)?

In case of the latter you’ld need to create a collection of images and add all the images (from the pages you’ld like to have the images from) to that collection…

@texnixe you are really really helpful. Always an answer for the questions. :slight_smile:

@bvdputte i mean i am using images on several pages. Now i tag the images on those several pages.
There is a link under (for example) gallery “show all images with ‘apple’”. Then i see all images of the entire site which have the tag “apple”.

Ok, then you should be able to achieve that by creating a collection with $site->index()->images() and then use the filter on that as @texnixe mentioned.

1 Like

Sorry to ask this awkward question… but how do i create a link to a page with a paramter in templates? I think i am to “dump” to search or find the answer.

Sorry :frowning:

Google is your friend :wink:

https://getkirby.com/docs/cheatsheet/helpers/params

I found that one, but that’s the fetching params method, isnt it?
My question was how are they generated inside the templates.

You can either build those URLs manually, or you can create a custom page method that does the job. Here is an example: https://getkirby.com/docs/cookbook/tags/#tagcloud

Ok, so there is not a function like:

echo html::a('gallery', $text = 'Link to tag', $urlparameter = array('imagetag' => 'XZY'));

$urlparameter was my idea.

No, but as I said, custom method to the rescue, here is an example: https://github.com/texnixe/kirby-custom-methods/blob/master/page-methods/custom-url.php (you would have to adapt this).

1 Like

Okay, thank you then.