Built-in Tests

2026-07-04

Used with the if keyword to test operands. For example:

{% if value is number %}
    Number
{% endif %}

defined

Tests whether a variable is defined.

undefined

Tests whether a variable is undefined.

odd

Tests whether the input is an odd number.

even

Tests whether the input is an even number.

string

Tests whether the input is a string.

number

Tests whether the input is a number.

divisible

Tests whether the input is divisible.

{% if rating is divisibleby(2) %}
    Divisible
{% endif %}

iterable

Tests whether the input can be iterated, such as a list or an object (key-value pairs).

object

Tests whether the input is an object (key-value pairs).

starting_with

Tests whether the input starts with the specified string.

{% if path is starting_with("x/") %}
    In section x
{% endif %}

ending_with

Tests whether the input ends with the specified string.

containing

Tests whether the input contains the specified value.

Input types:

  • String: whether it is a substring
  • List: whether it is an element
  • Object (key-value pairs): whether the key exists
{% if username is containing("xXx") %}
    Bad
{% endif %}

matching

Tests whether the input matches a regular expression.

{% if name is matching("^[Qq]ueen") %}
    Her Royal Highness, {{ name }}
{% elif name is matching("^[Kk]ing") %}
    His Royal Highness, {{ name }}
{% else %}
    {{ name }}
{% endif %}

empty

Tests whether the input is empty.

  • String with length 0
  • Number equal to 0
  • Empty array
  • false boolean