Twig

The flexible, fast, and secure
template engine for PHP

a Symfony Product
Docs Functions enum_cases
Docs for Twig version 3.x
Switch to another version: 1.x, 2.x

Questions & Feedback

License

Twig documentation is licensed under the new BSD license.

enum_cases

3.12

The enum_cases function was added in Twig 3.12.

enum_cases returns the list of cases for a given enum:

1
2
3
{% for case in enum_cases('App\\MyEnum') %}
    {{ case.value }}
{% endfor %}

When using a string literal for the enum argument, it will be validated during compile time to be a valid enum name.

Arguments

  • enum: The FQCN of the enum