I have an include which renders my posts in a certain format. I am passing the posts to the include like below:
{% 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
:
{% assign notjekyllposts = "" | split: "" %}
{% assign notjekyllposts = "" | split: "" %}
{% for apost in site.posts %}
jekyll
category adding them to the array: {% assign notjekyllposts = notjekyllposts | push: apost %}
include
tag 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 %}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.