Symfony2: preventing label display

I am trying to customize form layouts using Twig in symfony2. I'm trying to make a radio input that looks something like this ...

<label class=" required">Label name</label>
<span class="form-radio">
    <input type="radio" name="album_has_subalbums_1" /> Yes
</span>
<span class="form-radio">
    <input type="radio" name="album_has_subalbums_0" /> No
</span>

I redefined the block radio_widgetin my custom form theme as follows

{% block radio_widget %}
{% spaceless %}
    <span class='form-radio'>
        <input type="radio" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
    </span>
{% endspaceless %}
{% endblock radio_widget %}

However, this does the following markup:

<label class=" required">Label name</label>

<span class="form-radio">
    <input type="radio" id="album_has_subalbums_1" name="album[has_subalbums]" required="required" value="1">
</span>
<label for="album_has_subalbums_1" class=" required">Yes</label>

<span class="form-radio">
    <input type="radio" id="album_has_subalbums_0" name="album[has_subalbums]" required="required" value="0">
</span>
<label for="album_has_subalbums_0" class=" required">No</label>

Basically, a label is created for each radio input element to determine if the value for it is yes or no. I work with an existing design, so I can’t easily set up the html markup.

How can I prevent radio inputs from generating select texts as tags? I know that it calls a block field_labelinside, but, as you see, mine radio_widgetdoes not refer to it, so I lost a little how to prevent this behavior.

EDIT:

, , ... .., , , .

+5
1

, radio_widget, choice_widget one:

{% block choice_widget %}
{% spaceless %}
    {% if expanded %}
        <div {{ block('widget_container_attributes') }}>
        {% for child in form %}
            {{ form_widget(child) }}
            {{ child.get('label') | trans }} {# <- this is what you need #}
    {# leave the rest untouched #}

, .

+10

All Articles