When calling items from an array in a Liquid template, how do you call does not contain
or not in array
?
Asked
Active
Viewed 7.2k times
2 Answers
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
-
3My problem is I can't do something like this: `{% if input contains 'A' and input does not contain 'Z' %}` – Corey Jan 07 '19 at 18:57
-
14Use two nested conditions `{% if input contains 'A' %}{% unless input contain 'Z' %}` – David Jacquel Jan 07 '19 at 23:01
16
you could do something like this:
{% if collection.tags contains 'tag' %}
{% else %}
do stuff!
{% endif %}

Lucas Paiano
- 199
- 1
- 4