Jekyll:我们不能从每个 post 循环进入 posts(并显示列表)吗?

Jekyll: can't we loop in the posts (and display the list) from each post?

我想在类别页面中显示 post 的列表:此循环有效。 但我也想在这些 post 中的每一个上显示此列表:这是相同的循环,但它不起作用。

这是我的 Jekyll 循环:

{% for post in site.categories.[include.nomrecueil] reversed %}
  <li>{{ post.title }</li>
{% endfor %}

简短版

我的循环未提取 post 取决于所使用的布局。 我有以下结构:

categoryA
    | index.md
    | categoryB
        | index.md
        | _posts
            | article.md

我有两个包含相同循环的布局。我在 categoryB/index.md 中的循环工作正常,但在 article.md 中的循环不工作。知道为什么吗?我们不能从每个 post 循环进入 posts(并显示列表)吗?

详情

您可能需要更多信息,因此可以查看the repo if you need. The loop is at line 35 of the include nav-poemes.html which is included in two layouts: a) recueil.html and b) poem.html。循环在调用 recueil.html 布局的 index.md 中正确输出,但在调用 poem.html 布局的 article.md 中不正确。

我检查了循环中的包含参数 nomrecueil 是否在两个布局中都很好地传递了。在具有相同循环的第二个布局中未获取 posts... 我是在错误地使用 Jekyll 还是这是一个错误?

我不知道为什么...但这有效(这一定与 'contains' 语句有关):

{% assing includenomrecueil = include.nomrecueil %}
<ul>
  {% for category in site.categories %}
    {% assign catfirst = category | first %}
    {% if includenomrecueil contains catfirst %}
      {% for posts in category %}
        {% for p in posts reversed %}
          <li>...</li>
        {% endfor %}
      {% endfor %}
    {% endif %}
  {% endfor %}
</ul>

在您的代码中,变量通过了。我什至尝试向变量添加空格并删除它们(以确保它是一个字符串)。值得注意的是这有效:

{% for post in site.categories['fleurs-persistantes'] reversed %}
  <li>...</li>
{% endfor %}

即使 {{ include.nomrecueil }} 输出 fleurs-persistantes,同时这不起作用:

{% for post in site.categories[include.nomrecueil] reversed %}
  <li>...</li>
{% endfor %}

真奇怪!没看懂。