Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 choice_widget print only the label without markup?

Here is choice_widget template from Symfony2. I need to print the label text itself without markup, that is without calling form_label template but simply echoing the text.

The line to be sostituted is {{ form_label(child) }}. I've tried child.label but it's not working (there is no property label...). Also tried label but it prints the label of the whole widget, not the label of the current child element.

{% 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 %}

1 Answers

Form fields' attributes are stored in their ''vars'' property :

{{ child.vars.label }}
like image 187
AlterPHP Avatar answered Jan 05 '26 09:01

AlterPHP



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!