Does Liquid have a “does not contain” or “not in array” operator?

后端 未结 2 507
野性不改
野性不改 2021-02-02 06:10

When calling items from and array in a Liquid template, how do you call does not contain or not in array?

相关标签:
2条回答
  • 2021-02-02 06:18

    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 %}
    
    0 讨论(0)
  • 2021-02-02 06:34

    you could do something like this:

    {% if collection.tags contains 'tag' %}
    {% else %}
      do stuff!
    {% endif %}
    
    0 讨论(0)
提交回复
热议问题