Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Latest commit

 

History

History
31 lines (18 loc) · 864 Bytes

JinjaTests.md

File metadata and controls

31 lines (18 loc) · 864 Bytes

Tests

Within Jinja templates, you can use so-called tests. Basically, those are helpers usable in conditions after is keyword:

{% if loop.index is divisibleby 3 %}
    {# ... #}
{% endif %}

All of our filters are implemented in templates.tests module.

Bultin Tests

There are several widely used builtin tests directly in Jinja.

Custom Tests

not_empty

Checks if size of a collection is higher than 0

Example: items is not_empty

of_type

Checks if an object is instance of a certain type / class

Example: parent is of_type "ListQuestion"

💡 The name must be a string; however, it is case-insensitive. It also checks all superclasses.