我在Jekyll Liquid中有一个问题.
我有布局,我想从类别中显示页面.要显示类别,我使用page.categories变量.当我在括号{{page.categories}}中显示时是正确的.但我不知道,如何传递给循环?
{% for post in site.categories[page.categories] %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
{% for post in site.categories[{{page.categories}}] %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
不要工作.
如果我通过explicite:
{% for post in site.categories['cat1'] %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
有用.
我找到了另一个主题:
Jekyll site.categories.{{variable}}?
但它不起作用.
page.categories是一个列表(请参阅页面变量),因此您需要首先遍历它并将每个类别传递给您的问题循环:
{% for cat in page.categories %}
<h1>{{ cat }}</h1>
<ul>
{% for post in site.categories[cat] %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
</ul>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
这将首先按降序显示页面的第一个类别的所有帖子,然后按降序显示页面的第二个类别的所有帖子,依此类推.
| 归档时间: |
|
| 查看次数: |
1650 次 |
| 最近记录: |