I am trying to implement the twitter bootstrap 3 slideshow into a template, however, I cannot set the flag variable. The first div requires a class of active item
, and the rest should just have an item
class. How can I best achieve this in a for loop?
{% for review in reviews|slice:":3" %}
<div class="carousel-inner">
{% if forloop.counter0|divisibleby:"3" %}
<div class="active item">
{% else %}
<div class="item">
{% endif %}
<blockquote>
<p>{{ review.description }}</p>
</blockquote>
<label>{{ review.business }}</label>
</div>
{% endfor %}
What I have already tried:
How it works. The carousel is a slideshow for cycling through a series of content, built with CSS 3D transforms and a bit of JavaScript. It works with a series of images, text, or custom markup. It also includes support for previous/next controls and indicators.
In browsers where the Page Visibility API is supported, the carousel will avoid sliding when the webpage is not visible to the user (such as when the browser tab is inactive, the browser window is minimized, etc.).
Try this:
<div class="carousel-inner">
{% for review in reviews|slice:":3" %}
{% if forloop.first %}
<div class="active item">
{% else %}
<div class="item">
{% endif %}
<blockquote>
<p>{{ review.description }}</p>
</blockquote>
<label>{{ review.business }}</label>
</div>
{% endfor %}
</div>
forloop.first is True if this is the first time through the loop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With