我有一个包含以特定格式呈现我的帖子的内容。我正在将帖子传递到包含如下:
{% include post-list.html posts=site.posts %}
但是,我想在将某个类别传递给include之前将其过滤掉。有没有人有任何想法我怎么能做到这一点?
答案 0 :(得分:4)
您可以定义一个包含数组的变量,其中所有帖子都不包含特定类别,然后将其传递给包含,例如过滤包含类别jekyll
的帖子:
{% assign notjekyllposts = "" | split: "" %}
{% for apost in site.posts %}
jekyll
类别的广告,将其添加到数组中:{% assign notjekyllposts = notjekyllposts | push: apost %}
include
代码全部放在一起:
{% assign notjekyllposts = "" | split: "" %}
{% for apost in site.posts %}
{% unless apost.categories contains 'jekyll' %}
{% assign notjekyllposts = notjekyllposts | push: apost %}
{% endunless %}
{% endfor %}
{% include post-list.html posts=notjekyllposts %}