71

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

Luke
  • 4,825
  • 2
  • 30
  • 37
mike
  • 1,786
  • 2
  • 19
  • 31

2 Answers2

114

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 %}
David Jacquel
  • 51,670
  • 6
  • 121
  • 147
16

you could do something like this:

{% if collection.tags contains 'tag' %}
{% else %}
  do stuff!
{% endif %}
Lucas Paiano
  • 199
  • 1
  • 4