我有一个category.html
页面,它将循环播放特定类别的帖子。
{% for post in site.categories.tech %}
我想要显示的内容来自index.html
页面,当用户点击
{{ post.categories }}
这是从显示所有帖子的循环生成的。
{% for post in site.posts %}
我需要{{ post.categories }}
变量替换.tech
中的categories.html
{% for category in site.categories.{{ post.categories }} %}
我不知道如何将变量从index.html
传递到categories.html
答案 0 :(得分:0)
网站类别是一个对象,其中每个键都是类别名称。所以
{{ site.categories }}
输出如下内容:
{
"Category name" => [#, #, #, #, #, #, #],
"Another category name" => [#, #, #, #, #, #, #],
...
}
因此,方括号应该这样做。因此,如果您在index.html的前端问题上有
---
categories: tech
---
以下代码将在科技类别下呈现您的所有帖子。
{% for post in site.categories[post.categories] %}
{{ post }}
{% endfor %}
当然,如果您在前面有多个类别,这将无效,但我不知道您的用例。