enum
3.15
enum
函数在 Twig 3.15 中添加。
enum
提供对枚举的访问
1 2 3 4 5 6 7 8 9 10
{# display one specific case of a backed enum #}
{{ enum('App\\MyEnum').SomeCase.value }}
{# get all cases of an enum #}
{% for case in enum('App\\MyEnum').cases %}
{{ case.value }}
{% endfor %}
{# call any methods of the enum class #}
{{ enum('App\\MyEnum').someMethod() }}
当为 enum
参数使用字符串字面量时,它将在编译时被验证为有效的枚举名称。
参数
enum
: 枚举的 FQCN