Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 How to get the selected value from a select field with twig

I have a form that has some bootstrap nav-tabs and I need to repeat in every nav-tabs some info that I have preloaded from a select type field.

I can access to the Id with

{{  dump(form.proveedor.vars.value) }}

But I need the selected label value. How can I do this?

like image 263
Rodolfo Velasco Avatar asked Dec 15 '22 18:12

Rodolfo Velasco


1 Answers

Hopefully I get you question correctly.

    {% set label = '' %}
    {% for choice in form.proveedor.vars.choices %}
        {% if choice.value == form.proveedor.vars.value %}
            {% set label = choice.label %}
        {% endif %}
    {% endfor %}

    {{ label }}
like image 103
s7anley Avatar answered May 02 '23 17:05

s7anley