aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/twig/twig/doc/tests/constant.rst
blob: 8d0724a809da306d5ea39c65c675fb2e2b86de0e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
``constant``
============

.. versionadded: 1.13.1
    constant now accepts object instances as the second argument.

``constant`` checks if a variable has the exact same value as a constant. You
can use either global constants or class constants:

.. code-block:: jinja

    {% if post.status is constant('Post::PUBLISHED') %}
        the status attribute is exactly the same as Post::PUBLISHED
    {% endif %}

You can test constants from object instances as well:

.. code-block:: jinja

    {% if post.status is constant('PUBLISHED', post) %}
        the status attribute is exactly the same as Post::PUBLISHED
    {% endif %}