【问题标题】:Filter Array Liquid in JekyllJekyll 中的过滤器阵列液体
【发布时间】:2017-07-24 20:22:41
【问题描述】:

我有一个包含以某种格式呈现我的帖子。我将帖子传递给如下包含:

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

但是,我想在将某个类别传递给包含之前过滤掉它。有谁知道我该如何实现这一目标?

【问题讨论】:

    标签: jekyll liquid


    【解决方案1】:

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

    1. 我们创建数组{% assign notjekyllposts = "" | split: "" %}
    2. 循环所有帖子{% for apost in site.posts %}
    3. 过滤那些不包含jekyll的类别将它们添加到数组中:
      {% assign notjekyllposts = notjekyllposts | push: apost %}
    4. 将变量传递给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 %}
    

    【讨论】:

    • 感谢您的回复,但我想过滤掉一个类别。或者从数组中删除某个类别的所有帖子。
    猜你喜欢
    • 1970-01-01
    • 2020-07-08
    • 1970-01-01
    • 2012-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-23
    • 1970-01-01
    相关资源
    最近更新 更多