Robby Robby - 11 months ago 63
HTML Question

django 1.10 cycle to add hr tag every 4th element

I want to add an hr element every 4th child element in my html doc. This is what I have so far:

<div class="row blog-post">
{% for obj in object_list %}
<div class="col-sm-3">
<div class="thumbnail">
{% if obj.image %}
<img src="{{ obj.image.url }}" class="img-responsive"/>
{% endif %}
<div class="caption post-detail-item">
{% if obj.draft %}<h3>Staff only: <span style="color:red;">Draft</span></h3> {% endif %} {% if obj.publish > today %}<h3>Staff only: <span style="color:red;">Future Post</span></h3>{% endif %}
<h3><a href='{{ obj.get_absolute_url }}'>{{ obj.title }}</a><small> {{ obj.publish|timesince }}</small></h3>
{% if obj.user.get_full_name %}
<p>Author: {{ obj.user.get_full_name }}</p>
{% endif %}
{{ obj.get_markdown|truncatechars_html:350 }}
<p><a href="{{ obj.get_absolute_url }}" class="btn btn-primary" type="button">View</a></p>
{% cycle "" "<div class='col-sm-12'><hr/></div></div><div></div><div class='row'>" %}
{% endfor %}

The cycle bit I have there works to separate every second element, but I want it to be every 4th. Without it, I get 4 elements per line. This is what I want. Basically, I'm trying to make a standard height per column.

Answer Source
{% if forloop.counter0|divisibleby:4 %}
    <div class='col-sm-12'><hr/></div></div><div></div><div class='row'>
{% endif %}

More info about divisibleby: