Does Liquid have a "does not contain" or "not in array" operator?

JekyllLiquid

Jekyll Problem Overview


When calling items from an array in a Liquid template, how do you call does not contain or not in array?

Jekyll Solutions


Solution 1 - Jekyll

unless to the rescue !

Create an [A, B, C] array.

{% assign input = "A,B,C" | split:"," %}

unless print only if constrain is not met.

This prints nothing:

{% unless input contains 'A' %}No A{% endunless %}

This prints "No Z":

{% unless input contains 'Z' %}No Z{% endunless %}

Solution 2 - Jekyll

you could do something like this:

{% if collection.tags contains 'tag' %}
{% else %}
  do stuff!
{% endif %}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmikeView Question on Stackoverflow
Solution 1 - JekyllDavid JacquelView Answer on Stackoverflow
Solution 2 - JekyllLucas PaianoView Answer on Stackoverflow