A Shopify developer needs to add dynamic CSS classes (banner1, banner2, etc.) to carousel slides for Google Tag Manager event tracking purposes. The classes should be applied to the <a> tag within each slide.
Proposed Solution:
Another user suggested using Liquid’s forloop.index to generate sequential class names:
Current Issue:
The original poster implemented the suggested code inside the for block in section.blocks loop, but reports that only “banner1” is being added to all slides instead of incrementing (banner1, banner2, banner3, etc.).
Context:
The carousel contains 4 slides
Swiper.js is being used, which duplicates first/last slides
Goal is to track which banner users click most frequently
Status: The issue remains unresolved. The forloop.index approach should theoretically work (incrementing 1, 2, 3 for each block), but the implementation isn’t producing the expected sequential classes.
Summarized with AI on November 25.
AI used: claude-sonnet-4-5-20250929.
I have a carousel slideshow on my homepage banner on my shopify website. I want to add a class on each slide in the carousel for google tag manager event tracking. For example 1st banner will have a class of “banner1” 2nd will have “banner2” and so on. I have pasted the liquid code for the banner section. Can anyone lease guide me on how I can loop the slides in such a way that I can achieve this?
… and you’ve got more that one slide in the slideshow? forloop.index will start at one for the first block and increase by one for each block thereafter, so if you have 3 blocks each loop it will go 1, 2 then 3. If that number isn’t increasing, the loop isn’t increasing.