constant

constant 返回给定字符串的常量值:

1
2
{{ some_date|date(constant('DATE_W3C')) }}
{{ constant('Namespace\\Classname::CONSTANT_NAME') }}

也可以从对象实例中读取常量:

1
{{ constant('RSS', date) }}

使用 defined 检查是否定义了常数的测试:

1
2
3
{% if constant('SOME_CONST') is defined %}
    ...
{% endif %}