Loops 在jekyll集合上循环

Loops 在jekyll集合上循环,loops,jekyll,liquid,Loops,Jekyll,Liquid,我有以下代码 <div> {% for note in site.regnotes %} {% if note.regulationno == page.regulationno %} <p> {{ note.regulationno }} - {{ note.url }} </p> {% endif %} {% endfor %} </div> 我想我要做的是通过数组索引引用集合中的项。似乎无法获

我有以下代码

<div>
 {% for note in site.regnotes %}
   {% if note.regulationno == page.regulationno %}
     <p>
      {{ note.regulationno }} - {{ note.url }}
     </p>
   {% endif %}
 {% endfor %}
</div>

我想我要做的是通过数组索引引用集合中的项。似乎无法获得正确的语法。

既然您是一名程序员,您只需要知道您需要使用forloop.index0来知道您在for循环中的位置

代码将类似于:

<div>
 {% for note in site.regnotes %}
   {% assign current_index = forloop.index0 }}
   {% assign next_index = current_index | plus: 1 %}
   {% assign prev_index = current_index | minus: 1 %}
   {% if note.regulationno == page.regulationno %}
     <p>
      {{ note.regulationno }} - {{ note.url }}
     </p>
     {% if site.regnotes[prev_index] %}<a href="{{ site.regnotes[prev_index].url }}">prev</a>{% endif %}
     {% if site.regnotes[next_index] %}<a href="{{ site.regnotes[next_index].url }}">next</a>{% endif %}
   {% endif %}
 {% endfor %}
</div>

我不清楚你在找什么。您所在页面的URL将位于page.URL。至于下一页和上一页,Jekyll的内置分页功能只适用于帖子。
<div>
 {% for note in site.regnotes %}
   {% assign current_index = forloop.index0 }}
   {% assign next_index = current_index | plus: 1 %}
   {% assign prev_index = current_index | minus: 1 %}
   {% if note.regulationno == page.regulationno %}
     <p>
      {{ note.regulationno }} - {{ note.url }}
     </p>
     {% if site.regnotes[prev_index] %}<a href="{{ site.regnotes[prev_index].url }}">prev</a>{% endif %}
     {% if site.regnotes[next_index] %}<a href="{{ site.regnotes[next_index].url }}">next</a>{% endif %}
   {% endif %}
 {% endfor %}
</div>