mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-28 16:07:22 +00:00
ef7ade8ee3
* 3.x: (30 commits)
Make {} optional for the types tag
Remove the note about types mapping argument
Add a note on the types locality
Fix CS
Fix typos in the docs
Use spl_object_id() instead of spl_object_hash()
Add `LastModifiedExtensionInterface` and implementation in `AbstractExtension` to track modification of runtime classes
Bump version
Optimize NameExpression compilation
Fix typo in enum twig doc functions
Remove dead method in ModuleNode
Bump version
Prepare the 3.18.0 release
Add support for `Twig\Markup`
Fix unary operator precedence change
Replace Twigfiddle by the new Twig playground
Fix MacroNode $name argument can be overridden
Ignore exceptions from undefined handlers when using the guard tag
[Doc] Update the docs about attribute() function
Fix doc
...
26 lines
564 B
ReStructuredText
26 lines
564 B
ReStructuredText
``enum``
|
|
========
|
|
|
|
``enum`` gives access to enums:
|
|
|
|
.. code-block:: twig
|
|
|
|
{# 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() }}
|
|
|
|
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
|