blob: 21ce64f6cc6469896ab8a4c8a955f5c705e315a6 [file] [log] [blame]
==============
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`_:
.. sourcecode:: python
def is_even():
def wrapped(env, context, value):
return value % 2 == 0
return wrapped
Now you have to register that test on an environment:
.. sourcecode:: python
env.tests['even'] = is_even
.. _designer documentation: builtins.txt
.. _filter documentation: filters.txt