Working with logic operators
Besides comparison operators, we also have access to two logic operators, which allow us to combine multiple conditions to create complex statements. We can divide them into the two following groups:
- The
or
operator allows us to set multiple conditionals, where we must meet at least one of them:{% if collection.title == "Winter Shoes" or collection.all_products_count > 25 %} The collection name is Winter Shows, or the collection contains more than 25 products! {% endif %}
In the preceding example, we check whether the name of our collection is equal to
Winter Shoes
or if the collection contains more than25
products. If we have met at least one of these two conditions, the logic will returntrue
, and our message will be shown. Otherwise, the logic will returnfalse
, and the message will not be visible. - Similarly, the
and
operator allows us to set multiple conditions. However, for this operator...