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 →

Count images in gallery and act accordingly

Kaz van Kooten December 3, 2019 by Kaz van Kooten

Right. So I'm building a website where a collection entry can have a image gallery.

Some entries will have many images, some will only have a couple.

What I'd like to do, is have my template file count the amount of images the gallery contains and put them in a respective number of (Bootstrap) columns.

For example:

{{ gallery }}
{{ if count <= 3 }}
  <div class="col-md-4">
    <img src="{{ value }}">
{{ elseif count > 3 }}
  <div class="col-md-6">
    <img src="{{ value }}">
{{ /if }}
{{ /gallery }}

This doesn't work. It doesn't follow the count and so it doesn't switch. I'm pretty sure I'm missing something, I just don't know what. Index? Scope? And how should I use it?


Answered by Kaz van Kooten!
>>>>>>> Answered <<<<<<<
6 Replies