2016-05-19 9 views
0

私は以下のようなテンプレートを持っていますが、これまでグルーパーを使って私のショールームをアルファベット順にグループ化し、手紙を挿入しました。しかし、表示を簡単にするために、私はアルファベットの5文字ごとに私の列を作成するために5文字の各グループをフロートするクラス(詳細列)を挿入しようとしているので、私のデータを列に入れたいと思います。djangoテンプレート - forloop.counter 5つのエントリーごとに

ループカウンタをリセットする方法がわかりません。それを検索することは可能ではないようで、手作業で何かを書く必要がありますが、このクラスを挿入する必要があるかどうかはわかりません。

{% extends 'home/base-wide.html' %} 
{% block content %} 
<div id='content-body'> 
{% include 'service/sidebar.html' %} 
    <div class="float-left-content"> 
    {% regroup Showrooms by location.0 as Showrooms_by_letter %} 
    {% for letter_items in Showrooms_by_letter %} 
     {% if forloop.counter == 5 %} 
     <div class="detail-column"> 
     {% endif %} 
      <h4>{{ letter_items.grouper }}</h4> 
       {% for item in letter_items.list %} 
        <div class="letter-link"><a href="{% url 'service:showroom_detail' item.id %}">{{ item.location}}</a></div> 
       {% endfor %} 
     {% if forloop.counter == 5 %} 
     </div> 
     {% endif %}    
     {% endfor %} 
    </div> 
</div> 
{% endblock %} 

答えて

1

あなたは必要な場合があります:divisiblebyについて

{% if forloop.counter|divisibleby:"5" %} 

Djangoのドキュメントを。

+0

これはdjangoテンプレートエンジンでは機能しません –

+0

@DaniilRyzhkovはい、私が最初に答えたとき、私は気が抜けました。次回はもっと注意してください。 –

関連する問題