Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Carousel Implementation in Django

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
like image 432
iampj Avatar asked Nov 30 '14 22:11

iampj


People also ask

How does bootstrap carousel work?

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.

Why is Bootstrap carousel not sliding?

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.).


1 Answers

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

like image 138
simopopov Avatar answered Sep 28 '22 08:09

simopopov