2016-10-04 39 views
0

我想在我的html文檔中每第4個子元素添加hr元素。這是我迄今爲止:django 1.10週期添加hr標籤每4個元素

<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> 
       </div> 
      </div> 
     </div> 
    {% cycle "" "<div class='col-sm-12'><hr/></div></div><div></div><div class='row'>" %} 
    {% endfor %} 
</div> 

循環位我有那裏工作分開每第二個元素,但我希望它是每隔4。沒有它,我會得到每行4個元素。這就是我要的。基本上,我試圖爲每列製作標準高度。約divisibleby

回答

0

您可以通過兩個以上參數的循環標籤。例如:

{% cycle "" "" "" "<div..." %} 

這可能是整潔使用divisibleby作爲1GDST建議,我只是加入這個答案作爲替代。