Symfony2 choice_widget print only label without markup?

Here's a template choice_widget

from Symfony2. I need to print the text of the label without markup , i.e. without calling the template form_label

, but just echoing the text.

The string to be formed is {{ form_label(child) }}

. I've tried child.label

but it doesn't work (no property label ...). Also tried it label

, but it prints the label of the whole widget, not the label of the current item child

.

{% block choice_widget %}
{% spaceless %}
    {% if expanded %}
        <div {{ block('widget_container_attributes') }}>
        {% for child in form %}
            {{ form_widget(child) }}
            {{ form_label(child) }} {# here! #}
        {% endfor %}
        </div>
    {% else %}
        {# print <select> element #}
    {% endif %}
{% endspaceless %}
{% endblock choice_widget %}

      

+3


source to share


1 answer


Form field attributes are stored in the vars property:



{{ child.vars.label }}

      

+5


source







All Articles