常量
constant
检查变量是否具有与常量完全相同的值。您可以使用全局常量或类常量
1 2 3
{% if post.status is constant('Post::PUBLISHED') %}
the status attribute is exactly the same as Post::PUBLISHED
{% endif %}
您也可以从对象实例测试常量
1 2 3
{% if post.status is constant('PUBLISHED', post) %}
the status attribute is exactly the same as Post::PUBLISHED
{% endif %}