Bootstrap Carousel Implementation in Django
django, python, twitter-bootstrap
Solution
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
Problem
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: - Split Django Queryset in template for Bootstrap Carousel - Implementing twitter bootstrap carousel v2.3.2 - Dynamic carousel with django and bootstrap