constant
constant
返回给定字符串的常量值
1 2
{{ some_date|date(constant('DATE_W3C')) }}
{{ constant('Namespace\\Classname::CONSTANT_NAME') }}
您也可以从对象实例中读取常量
1
{{ constant('RSS', date) }}
检索对象的完全限定类名
1
{{ constant('class', date) }}
使用 defined
测试来检查常量是否已定义
1 2 3
{% if constant('SOME_CONST') is defined %}
...
{% endif %}