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:

Name

Use

Symbol

Equal

Check if two values are the same

==

Difference

Check if two values are different

!=

Greater than

Check if the value on the left side is larger than the value on the right side

>

Greater than or equal

Check if the value on the left side is larger or equal than the value on the right side

>=

Smaller than

Check if the value on the right side is larger than the value on the left side

<

Smaller than or equal

Check if the value on the right side is larger or equal than the value on the left side

<=

Or

Combine two or more of the above operators.

or

And

Combine two or more of the above operators

and

Contains

Check if a given string is part of a another string

contains

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.