There is also another custom TWIG filter |enum_constant
. It allows to use constants from ENUM classes in templates to print their values or to compare with other values.
{{ 'SHOOTING_GUARD'|enum_constant }}
{{ 'NORTH_WEST'|enum_constant }}
{% if player.position == 'SHOOTING_GUARD'|enum_constant %}
<span class="custom-class">{{ player.position }}</span>
{% endif %}
Same problem as for |readable_enum
filter is present here too. If some constant is defined in few ENUM classes then an exception will be thrown.
You can specify the correct class for this constant and it solves the problem.
{{ 'CENTER'|enum_constant('BasketballPositionType') }}
{{ 'CENTER'|enum_constant('MapLocationType') }}