Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 1 | ``constant`` |
| 2 | ============ |
| 3 | |
| 4 | ``constant`` checks if a variable has the exact same value as a constant. You |
| 5 | can use either global constants or class constants: |
| 6 | |
| 7 | .. code-block:: twig |
| 8 | |
| 9 | {% if post.status is constant('Post::PUBLISHED') %} |
| 10 | the status attribute is exactly the same as Post::PUBLISHED |
| 11 | {% endif %} |
| 12 | |
| 13 | You can test constants from object instances as well: |
| 14 | |
| 15 | .. code-block:: twig |
| 16 | |
| 17 | {% if post.status is constant('PUBLISHED', post) %} |
| 18 | the status attribute is exactly the same as Post::PUBLISHED |
| 19 | {% endif %} |