statamic / ideas

💡Discussions on ideas and feature requests for Statamic
https://statamic.dev
30 stars 1 forks source link

Assets tag - support filtering conditions (like Collection) #1003

Open wturrell opened 1 year ago

wturrell commented 1 year ago

Don't know how hard this is to do.

The motivation would be to avoid having to write conditionals in an assets loop.

There's also one case where I've found it a bit of a pain, when you want to pick a single random photo. The code below is nice, clean and efficient until you want to restrict the image by a property of some field (e.g. hide_from_gallery = false), at which point you have to start looping through them all...

{{ assets container="photos" limit="1" sort="random" }}
    <img alt="{{ alt }}" src="{{ glide:url w="1200" h="900" }}">
    <span>{{ partial:photo-caption }}</span>
{{ /assets }}