When calling items from an array in a Liquid template, how do you call does not contain
or not in array
?
Does Liquid have a "does not contain" or "not in array" operator?
78.9k Views Asked by mike At
3
There are 3 best solutions below
0

you could do something like this:
{% if collection.tags contains 'tag' %}
{% else %}
do stuff!
{% endif %}
0

I just wanted to loop throw product variants in collection / search result page and display current variant format, so in product-grid-item.liquid
file. In our webshop some formats have two version of colors, so I had to make to show formats only one.
I tried Lucas answer too, but it didn't work, don't understand, why.
So I solved another way: declared a string before loop and set it's value to the current variant format. Than check if next variant format is not the previously value.
{% assign currentFormat = '' %}
{%- for variant in product.variants -%}
{%- if currentFormat != variant.title -%}
<div>{{ variant_title }}</div>
{% assign currentFormat = variant.title %}
{%- endif -%}
{%- endfor -%}
unless
to the rescue !Create an [A, B, C] array.
unless
print only if constrain is not met.This prints nothing:
This prints "No Z":