mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-25 20:56:27 +00:00
ff4d01f940
The implementation contains an optimized implementation of the function for the common case of using a string literal as the argument. It will validate the enum existence during compilation and compile the code to use `MyEnum::cases()` directly.
22 lines
461 B
ReStructuredText
22 lines
461 B
ReStructuredText
``enum_cases``
|
|
==============
|
|
|
|
.. versionadded:: 3.12
|
|
|
|
The ``enum_cases`` function was added in Twig 3.12.
|
|
|
|
``enum_cases`` returns the list of cases for a given enum:
|
|
|
|
.. code-block:: twig
|
|
|
|
{% 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
|