在Jekyll过滤阵列液体

时间:2017-07-24 20:22:41

标签: jekyll liquid

我有一个包含以特定格式呈现我的帖子的内容。我正在将帖子传递到包含如下:

{% include post-list.html posts=site.posts %}

但是,我想在将某个类别传递给include之前将其过滤掉。有没有人有任何想法我怎么能做到这一点?

1 个答案:

答案 0 :(得分:4)

您可以定义一个包含数组的变量,其中所有帖子都不包含特定类别,然后将其传递给包含,例如过滤包含类别jekyll的帖子:

  1. 我们创建数组{% assign notjekyllposts = "" | split: "" %}
  2. 循环播放所有帖子{% for apost in site.posts %}
  3. 过滤那些不包含jekyll类别的广告,将其添加到数组中:
    {% assign notjekyllposts = notjekyllposts | push: apost %}
  4. 将变量传递给include代码
  5. 全部放在一起:

    {% 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 %}
    
相关问题