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 →

Getting the count/index of loop when outputting related field

Univers November 23, 2020 by Univers

On a site I'm building, I have the am using the following snippet to add a class to every third image in the loop:

{{ if count | mod:3 =='0' }}c-project-grid__item--portrait-fit{{ /if }}

On the home page, I'm outputting all the images of an asset fieldtype in that collection.

When I use the same snippet, it's counting within the related field, is there any method I can use to get the count/index of the scoped loop? I've tried scoping {{ index }} & {{ count }} but didn't have any luck. The basic gist is below:

     {{ collection:projects}}
  {{ featured_project_images }}
    <div class="c-project-grid__item c-project-grid__item{{ if width / height > 1 }}--landscape {{ else }}--portrait {{ count }}{{ if count | mod:3 =='0' }}c-project-grid__item--portrait-fit{{ /if }}{{ /if }} {{count}}">
      {{ responsive:url }}
  {{ /featured_project_images }}
{{ /collection:projects }}

Thanks for any help you can provide!

>>>>>>> Unanswered <<<<<<<
2 Replies