blob: 660bf870c0bca2d8fbd828b9fbbf228556709702 [file] [log] [blame]
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01001``constant``
2============
3
4``constant`` returns the constant value for a given string:
5
6.. code-block:: twig
7
8 {{ some_date|date(constant('DATE_W3C')) }}
9 {{ constant('Namespace\\Classname::CONSTANT_NAME') }}
10
11You can read constants from object instances as well:
12
13.. code-block:: twig
14
15 {{ constant('RSS', date) }}
16
17Use the ``defined`` test to check if a constant is defined:
18
19.. code-block:: twig
20
21 {% if constant('SOME_CONST') is defined %}
22 ...
23 {% endif %}