[英]Filter Array Liquid in Jekyll
I have an include which renders my posts in a certain format. 我有一个包含项,以某种格式呈现我的帖子。 I am passing the posts to the include like below:
我将帖子传递给如下所示的include:
{% include post-list.html posts=site.posts %}
However, I would like to filter out a certain category before passing it to the include. 但是,我想先过滤掉某个类别,然后再将其传递给包含。 Does anyone have any ideas how I can achieve this?
有谁知道我如何实现这一目标?
You can do it defining a variable containing an array with all the posts not containing a specific category and then passing that to includes, for example to filter posts containing the category jekyll
: 您可以定义一个包含数组的变量,该数组的所有帖子均不包含特定类别,然后将其传递给包括,例如过滤包含
jekyll
类别的帖子:
{% assign notjekyllposts = "" | split: "" %}
{% assign notjekyllposts = "" | split: "" %}
{% assign notjekyllposts = "" | split: "" %}
{% for apost in site.posts %}
{% for apost in site.posts %}
jekyll
category adding them to the array: jekyll
类别的那些,将它们添加到数组中: {% assign notjekyllposts = notjekyllposts | push: apost %}
include
tag include
标记 Putting it all together: 放在一起:
{% 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 %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.