Yaffs site version 1.1
[yaffs-website] / vendor / twig / twig / doc / functions / constant.rst
1 ``constant``
2 ============
3
4 .. versionadded: 1.12.1
5     constant now accepts object instances as the second argument.
6
7 .. versionadded: 1.28
8     Using ``constant`` with the ``defined`` test was added in Twig 1.28.
9
10 ``constant`` returns the constant value for a given string:
11
12 .. code-block:: jinja
13
14     {{ some_date|date(constant('DATE_W3C')) }}
15     {{ constant('Namespace\\Classname::CONSTANT_NAME') }}
16
17 As of 1.12.1 you can read constants from object instances as well:
18
19 .. code-block:: jinja
20
21     {{ constant('RSS', date) }}
22
23 Use the ``defined`` test to check if a constant is defined:
24
25 .. code-block:: jinja
26
27     {% if constant('SOME_CONST') is defined %}
28         ...
29     {% endif %}