Test Functions



In addition to filters, Jinja also supports test functions. Test functions always return either True or False. Inside the template they are available using the is operator.

Jinja comes with some builtin tests listed in the designer documentation.

Writing Test Functions

Test functions look exactly like filters mentioned in the filter documentation:

def is_even():
    def wrapped(env, context, value):
        return value % 2 == 0
    return wrapped

Now you have to register that test on an environment:

env.tests['even'] = is_even