Array contains an element, or not
Snippet
Instead of being asleep at 20:04 on 12 May 2022, kitt created this:
Of course, the code syntax highlighter doesn't support Liquid. :\
Use contains
to check existence and unless
for not, unless you want to use both states.
Doen't contain: {% assign input = "A,B,C" | split:"," %} This prints nothing: {% unless input contains 'A' %}No A{% endunless %} This prints "No Z": {% unless input contains 'Z' %}No Z{% endunless %} Both states: {% if collection.tags contains 'tag' %} loop over tags {% else %} don't loop over stuff {% endif %}
Add new comment