corywc
corywc

Reputation: 11

How to use 'where' filters with an 'or' operator

I'm creating a Liquid template where I look for documents within a collection where a given metadata tag is "valueA" OR "valueB".

I've tried the following:

{% assign item = site.rn | where: "type", "typeA" OR "typeB" %}
{% assign item = site.rn | where: "type", "typeA" "typeB" %} 
{% assign item = site.rn | where: "type", "typeA" | where: "type", "typeB" %}

None of the above examples are returning both items where type=typeA AND items where type=typeB. The first two return only items where type=typeA. The third does not return anything because there are no items where type=typeA and type=typeB.

Upvotes: 1

Views: 464

Answers (1)

David Jacquel
David Jacquel

Reputation: 52789

Edit

It seems that binary operator in where_expwill not be supported before Jekyll 4.

As you've pointed in your comment under your question you can loop over your collection and feed an array depending on a if control structure.

{% assign items = "" | split:"" %}

{% for item in site.rn %}
  {% if item.type == 'typeA' or item.type == 'typeB' %}
    {% assign items = items | push: item %}
  {% endif %}
{% endfor %}

end edit

This will work in Jekyll 4

You can try the jekyll specific `where_exp' liquid filter (see documentation).

{% assign item = site.rn | where: "item", "item.type == 'typeA' or item.type == 'typeB'" %}

Upvotes: 2

Related Questions