Hello! I have a piece of code

{% for product in products %} <li class="col-xs-6 col-sm-4 col-md-3 col-lg-3">{% render_product product %}</li> {% endfor %} 

which displays in turn the desired product. I need to insert the line feed after every third product

 <br class="clr" /> 

So that the goods do not move, I'm new to Django, waiting for support)

    2 answers 2

    You can also use the cycle tag

     {% for product in products %} <li class="col-xs-6 col-sm-4 col-md-3 col-lg-3">{% render_product product %}</li> {% cycle '' '' '<br class="clr" />' %} {% endfor %} 

    as a result, every third iteration will be with an insert br

      If the current iteration is divided by 3 without a remainder, then output the tag:

       {% for product in products %} <li class="col-xs-6 col-sm-4 col-md-3 col-lg-3">{% render_product product %}</li> {% if forloop.counter|divisibleby:3 %}<br class="clr" /> {% endif %} {% endfor %}