Reputation: 855
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?
Upvotes: 4
Views: 11769
Reputation: 2498
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 }}
Upvotes: 12
Reputation: 2049
selected is an attribute, so you can access it with:
{{ dump(form.proveedor.vars.attr["selected"]) }}
Then you can with if sentence check if option has attr equal to selected. If yes then do something, like echo label.
{% if form.proveedor.vars.attr["selected"] == "selected" %}
{# do something, like echo label #}
{% endif %}
Upvotes: 0