Changing a html class after the first item in a Hugo loop

Viewed 45

So I am making a review carousel using Bootstrap and Hugo, I've got code that breaks down into this:

{{ range seq 1 3 (len site.Data.reviews) }}
  ...
  {{ range seq . (add . 2) }}
    {{ with (index site.Data.reviews (string .)) }}
      {{ .des }}
    {{ end }}
  {{ end }}
  ...
{{ end }}

So there's two loops, one to make the slides for the carousel, and the other to fill the slides with data files. The issue is I need to delete the active class and adjust the data-bs-interval input on the next few slides I thought about making an if statement but I'm not sure how to replace the first div with one that doesn't have the active class after that in whats generated.

1 Answers

I don't know if this is the best solution to it, instead of editing the loop I wrote a bit of javascript:

var addActive = document.getElementById('carouselExampleDark').getElementsByClassName('carousel-item')[0];
    addActive.classList.add("active");

That works for my use case so I'll leave it at that.

Related