What Shell am I Using?« an older post
a newer one »Shopify Liquid for loop

Array contains an element, or not

Snippet

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

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.