Array contains an element, or not
Snippet
Posted by kitt at 20:04 on 12 May 2022
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