私は、desk.com テンプレートのカスタマイズに利用できる Liquid テンプレートを使用しています。
for ループでコレクションを繰り返し処理しているときに、コレクションの途中でインデックスをキャッチして、別の列に分割しようとしています。
これが私のコードスニップです:
{% capture half_topics %}{{ topics_count | divided_by:2 }}{% endcapture %}
<div>TEST Topics Count: {{ topics_count }}</div>
<div>TEST Half: {{ half_topics }}</div>
<div class="bt-column">
{% for topic in topics %}
<div>TEST Forloop Index: {{ forloop.index }}</div>
<div>TEST Are we there yet?: {{ this_index }}</div>
{% if forloop.index == half_topics %}
<div>TEST This is where a column split should go</div>
</div><div class="bt-column">
{% endif %}
<h4>{{ topic.name }}</h4>
{% endfor %}
</div>
出力の一部を次に示します。
TEST Topics Count: 7
TEST Half: 3
TEST Forloop: 1
TEST Are we there yet?: 1
Topic 1
TEST Forloop: 2
TEST Are we there yet?: 2
Topic 2
TEST Forloop: 3
TEST Are we there yet?: 3
Topic 3
TEST Forloop: 4
TEST Are we there yet?: 4
Topic 4
(私が思うに)の出力はブール値である必要があることに注意してください。代わりに、forloop.indexと同じ整数です。その比較式がそのような出力値でも機能するかどうかはわかりませんが、いずれにせよ、私が知る限り、正しいブール値に評価されていないことがわかります。また、段区切りが発生していないこともわかります。
Google はどうやらこれについて何も言うことがないか、または私は Google に対してお粗末です。:)