Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame^] | 1 | ``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 | |
| 11 | You can read constants from object instances as well: |
| 12 | |
| 13 | .. code-block:: twig |
| 14 | |
| 15 | {{ constant('RSS', date) }} |
| 16 | |
| 17 | Use 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 %} |