I want my carousel-item at least it have 5 cards. But it only has one card in each carousel-item.
What should I do.:
{% for knowledge in knowledges %}
<div class="carousel-inner">
{% for photo in photo01s|slice:":5" %}
<div class="carousel-item {% if forloop.first %}active{% endif %}">
<div class="row">
{% if photo.category01 == knowledge %}
<div class="card" style="background-image: url('{{ photo.image01.url }}');"></div>
{% endif %}
</div>
</div>
{% endfor %}
</div>
{% endfor %}
I have tried several ways but it does not work.
2
Answers
Let’s assume that you want 5 photos of each knowledge and assuming you have more than 5 photos of each knowledge, so:
class carousel-inner outside the for loop.
Now you will atleast 5 photos of each knowledge in carousel.
You should iterate over
knowledges
and within each knowledge, iterate through the corresponding photos until you have at least 5 cards, so:Now it will loop through each knowledge and then within each knowledge, it will loop through photos until it finds 5 cards.