skip to Main Content

Within the product page, I would like to hide a certain element if the current product isn’t associated with any collection. Is there any way to check it with Liquid ?

2

Answers


  1. {% if 0 == product.collections | size %}
     !! put your code here !!
    {% endif %}
    

    Or

    {% for _ in  product.collections   %}
    {% else %}
     !! put your code here !!
    {% endif %}
    
    Login or Signup to reply.
  2. The object product.collections is an array containing all collections where the product is listed.

    So you may use this:

    {% if product.collections.size < 1 %}
        Do something
    {% endif %}
    

    Documentation about arrays here:
    https://shopify.dev/api/liquid/filters#size

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search