Understand Liquid operators
Liquid has access to all common logical and comparison operators. These operators can be used in tags such as if and unless.
Basic operators
== | Equals |
---|---|
!= | Doesn't equal |
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
or | Condition A or condition B |
and | Condition A and condition B |
contains
contains tests for the presence of a substring within a string.
{% if page.title contains 'Product' %}
The title of this page contains the word Product.
{% endif %}
contains can also test for the presence of a string within an array of strings.
startswith
startswith tests whether a string starts with a given substring.
{% if page.title startswith 'Profile' %}
This is a profile page.
{% endif %}
endswith
endswith tests whether a string ends with a given substring.
{% if page.title endswith 'Forum' %}
This is a forum page.
{% endif %}