F
F
Friend2016-11-17 11:53:10
Django
Friend, 2016-11-17 11:53:10

How to implement an if condition on index 4 in html?

I don’t know how to find out the index of the iterated object in order to build a chain of conditions for the transition.
Example:

{% for i in table %} 
<!-- Сюда 4 элемента-->
<div>
<!-- И сюда все остальные элементы -->
{%endfor%}

Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2016-11-17
@Tiran_94

{% for i in table %} 
    {% if forloop.counter < 5 %}
<!-- Сюда 4 элемента-->
    {% else %}
<!-- И сюда все остальные элементы -->
    {% endif %}
{%endfor%}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question