Twig

灵活、快速且安全
PHP 模板引擎

a Symfony Product
Docs Tests constant
您正在阅读 Twig 3.x 的文档。切换到 Twig 1.x, 2.x 的文档。

问题与反馈

许可证

Twig 文档 根据新的 BSD 许可证获得许可。

常量

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 %}