module documentation

Built-in template tests used with the is operator.
Constant TESTS Undocumented
Function test​_boolean Return true if the object is a boolean value.
Function test​_defined Return true if the variable is defined:
Function test​_divisibleby Check if a variable is divisible by a number.
Function test​_escaped Check if the value is escaped.
Function test​_even Return true if the variable is even.
Function test​_false Return true if the object is False.
Function test​_filter Check if a filter exists by name. Useful if a filter may be optionally available.
Function test​_float Return true if the object is a float.
Function test​_in Check if value is in seq.
Function test​_integer Return true if the object is an integer.
Function test​_iterable Check if it's possible to iterate over an object.
Function test​_lower Return true if the variable is lowercased.
Function test​_mapping Return true if the object is a mapping (dict etc.).
Function test​_none Return true if the variable is none.
Function test​_number Return true if the variable is a number.
Function test​_odd Return true if the variable is odd.
Function test​_sameas Check if an object points to the same memory address than another object:
Function test​_sequence Return true if the variable is a sequence. Sequences are variables that are iterable.
Function test​_string Return true if the object is a string.
Function test​_test Check if a test exists by name. Useful if a test may be optionally available.
Function test​_true Return true if the object is True.
Function test​_undefined Like defined but the other way round.
Function test​_upper Return true if the variable is uppercased.
TESTS =

Undocumented

Value
{'odd': test_odd,
 'even': test_even,
 'divisibleby': test_divisibleby,
 'defined': test_defined,
 'undefined': test_undefined,
 'filter': test_filter,
 'test': test_test,
...
def test_boolean(value):

Return true if the object is a boolean value.

New in version 2.11.
Parameters
value:t.AnyUndocumented
Returns
boolUndocumented
def test_defined(value):

Return true if the variable is defined:

{% if variable is defined %}
    value of variable: {{ variable }}
{% else %}
    variable is not defined
{% endif %}

See the default filter for a simple way to set undefined variables.

Parameters
value:t.AnyUndocumented
Returns
boolUndocumented
def test_divisibleby(value, num):
Check if a variable is divisible by a number.
Parameters
value:intUndocumented
num:intUndocumented
Returns
boolUndocumented
def test_escaped(value):
Check if the value is escaped.
Parameters
value:t.AnyUndocumented
Returns
boolUndocumented
def test_even(value):
Return true if the variable is even.
Parameters
value:intUndocumented
Returns
boolUndocumented
def test_false(value):

Return true if the object is False.

New in version 2.11.
Parameters
value:t.AnyUndocumented
Returns
boolUndocumented
@pass_environment
def test_filter(env, value):

Check if a filter exists by name. Useful if a filter may be optionally available.

{% if 'markdown' is filter %}
    {{ value | markdown }}
{% else %}
    {{ value }}
{% endif %}
New in version 3.0.
Parameters
env:EnvironmentUndocumented
value:strUndocumented
Returns
boolUndocumented
def test_float(value):

Return true if the object is a float.

New in version 2.11.
Parameters
value:t.AnyUndocumented
Returns
boolUndocumented
def test_in(value, seq):

Check if value is in seq.

New in version 2.10.
Parameters
value:t.AnyUndocumented
seq:t.ContainerUndocumented
Returns
boolUndocumented
def test_integer(value):

Return true if the object is an integer.

New in version 2.11.
Parameters
value:t.AnyUndocumented
Returns
boolUndocumented
def test_iterable(value):
Check if it's possible to iterate over an object.
Parameters
value:t.AnyUndocumented
Returns
boolUndocumented
def test_lower(value):
Return true if the variable is lowercased.
Parameters
value:strUndocumented
Returns
boolUndocumented
def test_mapping(value):

Return true if the object is a mapping (dict etc.).

New in version 2.6.
Parameters
value:t.AnyUndocumented
Returns
boolUndocumented
def test_none(value):
Return true if the variable is none.
Parameters
value:t.AnyUndocumented
Returns
boolUndocumented
def test_number(value):
Return true if the variable is a number.
Parameters
value:t.AnyUndocumented
Returns
boolUndocumented
def test_odd(value):
Return true if the variable is odd.
Parameters
value:intUndocumented
Returns
boolUndocumented
def test_sameas(value, other):

Check if an object points to the same memory address than another object:

{% if foo.attribute is sameas false %}
    the foo attribute really is the `False` singleton
{% endif %}
Parameters
value:t.AnyUndocumented
other:t.AnyUndocumented
Returns
boolUndocumented
def test_sequence(value):
Return true if the variable is a sequence. Sequences are variables that are iterable.
Parameters
value:t.AnyUndocumented
Returns
boolUndocumented
def test_string(value):
Return true if the object is a string.
Parameters
value:t.AnyUndocumented
Returns
boolUndocumented
@pass_environment
def test_test(env, value):

Check if a test exists by name. Useful if a test may be optionally available.

{% if 'loud' is test %}
    {% if value is loud %}
        {{ value|upper }}
    {% else %}
        {{ value|lower }}
    {% endif %}
{% else %}
    {{ value }}
{% endif %}
New in version 3.0.
Parameters
env:EnvironmentUndocumented
value:strUndocumented
Returns
boolUndocumented
def test_true(value):

Return true if the object is True.

New in version 2.11.
Parameters
value:t.AnyUndocumented
Returns
boolUndocumented
def test_undefined(value):
Like defined but the other way round.
Parameters
value:t.AnyUndocumented
Returns
boolUndocumented
def test_upper(value):
Return true if the variable is uppercased.
Parameters
value:strUndocumented
Returns
boolUndocumented