Operators

Video outline

Operators are used to define a range, scope or limitation, just like a mathematical equation.
Control flow tags create conditions that decided whether blocks of code should be executed and they can be used to test or compare a result.

What operators can be used in liquid:

NameUseSymbol
EqualCheck if two values are the same==
DifferenceCheck if two values are different!=
Greater thanCheck if the value on the left side is larger than the value on the right side>
Greater than or equalCheck if the value on the left side is larger or equal than the value on the right side>=
Smaller thanCheck if the value on the right side is larger than the value on the left side<
Smaller than or equalCheck if the value on the right side is larger or equal than the value on the left side<=
OrCombine two or more of the above operators.or
AndCombine two or more of the above operatorsand
ContainsCheck if a given string is part of a another stringcontains

Examples

In this example if blank is equal to or greater or the same or different than 10:

{% if  == 10 %}We are the same as 10{% endif %}
{% if  != 10 %}We are different from 10{% endif %}
{% if  > 10 %}greater than 10{% endif %}
{% if  <= 10 %}greater than or equal to 10{% endif %}
{% if  < 10 %}smaller than 10{% endif %}
{% if  <= 10 %}smaller than or equal to 10{% endif %}

If the equation meets it will print out the text that’s following afterwards

In this second example we want to check if an input field is showing profitability or not.

{% if  input custom.pl.check default:1 %}

**Are we profitable?**

{% if  custom.pl.check > 0 %}Profitable
{% else %}Loss{% endif %}

Conclusion

  • Operators are used to define a range, scope or limitation
  • Operators are used to compare values. In combination with control flow tags you can put some logic in your coding

📘

Equal than ==

Remember we use a double-equal sign to show that we’re checking a value, rather than setting it equal to something, like we would with a variable.