Files
Twig/doc/functions/constant.rst
T
Fabien Potencier 05e1c68c4b Merge branch '1.x' into 2.x
* 1.x:
  added some more tests
  added 'is defined' support for constant
  added 'is defined' support for block()
  Add test to check if a block exists
2016-11-11 13:50:46 -08:00

24 lines
487 B
ReStructuredText

``constant``
============
``constant`` returns the constant value for a given string:
.. code-block:: jinja
{{ some_date|date(constant('DATE_W3C')) }}
{{ constant('Namespace\\Classname::CONSTANT_NAME') }}
You can read constants from object instances as well:
.. code-block:: jinja
{{ constant('RSS', date) }}
Use the ``defined`` test to check if a constant is defined:
.. code-block:: jinja
{% if constant('SOME_CONST') is defined %}
...
{% endif %}