Reference
Tests
Built-in tests for use with is.
A test checks a value and returns true or false. Write it after is, or is not to flip the result.
{% if items is not empty %}
defined
True when a variable or property exists. It never raises a strict mode error, so it is the safe way to check for optional data.
page.kiln
{% if page.subtitle is defined %}{{ page.subtitle }}{% else %}No subtitle{% endif %}
Output
No subtitle
null
True when the value is null or undefined.
page.kiln
{{ page.image is null ? "No image" : "Has image" }}
Output
No image
empty
True when the value is empty: null, false, an empty string, array, hash, set or map. 0 is not empty.
page.kiln
{{ [] is empty }} {{ 0 is empty }}
Output
true false
even and odd
True when the value is an even or odd whole number.
page.kiln
{% for n in 1..4 %}{{ n }} is {{ n is even ? "even" : "odd" }}. {% endfor %}
Output
1 is odd. 2 is even. 3 is odd. 4 is even.
iterable
True for arrays, hashes, sets, maps and other values for can loop over. Strings are not iterable.
page.kiln
{{ [1, 2] is iterable }} {{ "abc" is iterable }}
Output
true false
divisible by
True when the value is a multiple of the argument.
page.kiln
{% for n in 1..6 %}{{ n }}{% if n is divisible by(3) %} |{% endif %} {% endfor %}
Output
1 2 3 | 4 5 6 |