1

我正在使用 Liquid 模板,这些模板可用于自定义desk.com 模板。

在 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 相同的整数。我不知道该比较表达式是否甚至可以在这样的输出值中工作,但无论如何,据我所知,您可以看到它没有计算为正确的布尔值。您还可以看到分栏从未发生过。

谷歌显然对此无话可说,或者我在谷歌上很糟糕。:)

4

0 回答 0