]>
Commit | Line | Data |
---|---|---|
4f5b44bd NL |
1 | ``constant`` |
2 | ============ | |
3 | ||
4 | .. versionadded: 1.13.1 | |
5 | constant now accepts object instances as the second argument. | |
6 | ||
7 | ``constant`` checks if a variable has the exact same value as a constant. You | |
8 | can use either global constants or class constants: | |
9 | ||
10 | .. code-block:: jinja | |
11 | ||
12 | {% if post.status is constant('Post::PUBLISHED') %} | |
13 | the status attribute is exactly the same as Post::PUBLISHED | |
14 | {% endif %} | |
15 | ||
16 | You can test constants from object instances as well: | |
17 | ||
18 | .. code-block:: jinja | |
19 | ||
20 | {% if post.status is constant('PUBLISHED', post) %} | |
21 | the status attribute is exactly the same as Post::PUBLISHED | |
22 | {% endif %} |