When calling items from an array in a Liquid template, how do you call does not contain
or not in array
?
You can directly create a new empty array controllers and concat to it your controllerName converted into an array using the workaround split:'' . The result is directly an array, without the extra string manipulations.
Liquid objects can return one of seven basic types: String, Number, Boolean, Array, Dictionary, DateTime, or Null. Liquid variables can be initialized by using the assign or capture tags.
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 %}
you could do something like this:
{% if collection.tags contains 'tag' %} {% else %} do stuff! {% endif %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With