Builtin Test

Used to make a test judgment on an operand using the if keyword. For example.

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

defined

Returns true if the variable is defined.

undefined

Returns true if the variable is undefined

odd

Returns true for odd numbers

even

Returns true for even numbers

string

Returns true if the character is long

number

is a number

divisible

Returns true if the number is divisible

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

iterable

Can be iterated through a loop to return true. Such as lists, objects (key-value pairs).

object

Returns true if the object is a key-value pair.

starting_with

Returns true when starting with the specified string.

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

ending_with

Returns true at the end of the specified string, called as starting_with.

containing

Returns true if the specified value is contained.

Input type:

  • String: is its substring returns true
  • List: true if it is an element
  • Object (key-value pair): key name exists return true
{% if username is containing("xXx") %}
    Bad
{% endif %}

matching

Returns true if the match is successful.

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

empty

Returns true if the input is empty.

  • String length is zero
  • The number equals zero
  • empty array
  • false Boolean