New: Learn Statamic on Laracasts!

We've retired the forum in favor of GitHub Discussions.

New conversations can be started on GitHub. Existing conversations will remain for a while longer.

Head over to GitHub →

Filtering an assets tag using `get`

Mike Harrison March 27, 2020 by Mike Harrison

Hi,

I have an asset container called "Gallery Images", the fieldset for which looks like this:

sections:
  main:
    display: Main
    fields:
      title:
        display: Title
        type: text
        localizable: true
      alt_text:
        type: text
        display: 'Alt Text'
      caption:
        type: text
        display: Caption
        instructions: 'This appears when the image is viewed in the gallery'
      gallery-category:
        max_items: 1
        taxonomy: gallery-category
        mode: tags
        type: taxonomy
        display: Category
taxonomies: true
hide: true
title: 'Gallery Image'

Which is generating gallery_images.yaml which looks like this:

path: gallery-images
url: /gallery-images
title: 'Gallery Images'
fieldset: gallery_image
assets:
  my_lovely_horse.jpg:
    gallery-category: lovely-horses
  my_lovely_horse_running_through_the_field.jpg:
    gallery-category: fields
...

Then on a page on my site I am allowing the editor to select images from this container, with the following:

gallery_images:
        container: gallery_images
        folder: /
        restrict: false
        type: assets
        display: 'Gallery Images'

This displays as a little image gallery on the page, using this in the template:

{{ assets:gallery_images sort="random" }}
...html here...
{{ /assets:gallery_images }}

Which is all working great. Now I would like to filter this by the taxonomy of the image. I also need to do this based on a query string in the URL. Is this possible? I have successfully got the query I need using {{ get:filter }}, but am unsure what to do with it.

Any help would be hugely appreciated as I am a bit stuck

Answered by Mike Harrison!
>>>>>>> Answered <<<<<<<
3 Replies
3 Followers