mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-28 02:57:12 +00:00
def4abbd5e
It may be obvious, but I first thought initializing an BackendEnum with a certain value could be possible with `enum(FQCN, value)`, but it does not, it always returns the first case instance (if exists). Instead, `enum(FQCN).from(value)` must be used, I think it's worth to improve `enum()` examples.
23 lines
514 B
ReStructuredText
23 lines
514 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\\CardSuite') %}
|
|
{{ case.value }}
|
|
{% endfor %}
|
|
{# "clubs", "spades", "hearts", "diamonds" #}
|
|
|
|
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
|