Learning the comparison operators
With Liquid, we have access to seven comparison operators, which we can combine to create any type of logical flow that our code requires. Let's review them as follows:
- The
==
operator allows us to check whether the element we are comparing is equal to some value:{% if collection.title == "Winter Shoes" %} Winter Shows collection found! {% endif %}
If
collection.title
is strictly equal to our string of"Winter Shows"
, the logic returnstrue
, and we will see our message shown. Otherwise, the logic returnsfalse
. Note that comparison will only returntrue
if the string is an exact match, including the text case. - The
!=
operator works similarly to the previous operator. The difference is that this operator checks whether the element we are comparing is not equal to some value:{% if collection.title != "Winter Shows" %} Winter Shows collection is not found! {% endif %}
As with the previous...