Skip to content
This day’s portion

Improving where filters in Jekyll

The Liquid where filter selects items from arrays so you don’t have to loop through an entire set. In Jekyll this is useful for creating things like category listings, as well as cutting down on site build times.

So you might output a list of all posts in the web category like this:

That’s good, if a little restrictive. where only lets you filter for conditions where something equals something else (in this case where the category equals web).

There are times when you might want to filter for all articles not in the web category. For this, you need the where_exp filter.

where_exp lets you use expressions and operators in filters, such as or, and and !=, so you could also use it to filter for all posts in the web and libraries categories. Here’s how you filter for everything not in the web category:

Liked this?

Consider subscribing to the RSS feed. That way, you’ll get notified whenever I post anything new. If you’re not sure about RSS feeds, I wrote a guide to RSS.

https://www.thisdaysportion.com/where-exp-improve-array-filtering-jekyll/

Previous post

Next post

Comments

Add a comment

Required fields marked * I won’t publish or share your email address. Privacy statement.

Comments are moderated and won’t appear straight away. Subscribe to the comments feed to see when new comments are published.