I want to use a bootstrap 5 carousel in an alchemy element with nested images. In order to do this, i need to get the sortorder or index of the iteration, as the carousel expects an "active" tag on the first element.
<%= element_view_for(image_slide, tag: false) do |el| %>
<div class="carousel-item active">
<%= el.render :image, {}, class: "d-block w-100 #{"active" if index == 0}" %>
</div>
<% end %>
How can i achieve this?
In every Rails partial that rendered by the collection renderer you have a local variable called
<the-partial-name>_counteravailable.From https://guides.rubyonrails.org/layouts_and_rendering.html#local-variables
Just make sure that the parent element (I'm assuming an
imager_slider) uses the collection partial renderer.Then you can use