标记标记内的输出标记

时间:2014-08-04 16:15:16

标签: jekyll liquid

我的问题是如何重写此输出标记(确实有效)

{{ forloop.index0 | modulo:4 }}

这样它就可以在标记标记内部使用(它不起作用)。

{% if forloop.index0 | modulo:4 == 0 %}

2 个答案:

答案 0 :(得分:0)

编辑回答:

对于此示例,我使用自定义数组,但该数组可以是 site.pages site.posts site.data.somedatas

{% assign words = "zero,one,two,three,four,five" | split: ',' %}

然后处理单词数组:

<ol>
{% for word in words %}

  {% comment %} Here we assign the filtered array to myTest {% endcomment %}
  {% assign myTest = forloop.index0 | modulo:4 %}

  {% comment %} then we process the filtered array {% endcomment %}
  {% if myTest == 0 %}
    <li>
      <h4>Test passing (index = {{ forloop.index0 }} &gt;&gt; modulo = {{ myTest }})</h4>
    </li>
  {% else %}
    <li>
      <h4>test NOT passing (index = {{ forloop.index0 }} &gt;&gt; modulo = {{ myTest }})</h4>
    </li>
  {% endif %}

{% endfor %}
</ol>

这适用于Jekyll 2.2.0,当前的Github页面版本。

答案 1 :(得分:0)

这就是最终的工作(大卫帮助我开始)。

{% assign mod = forloop.index0 | modulo:4 %}
{% if mod == 0 %}
    <!-- Do stuff -->
{% endif %}