Symfony2 - How to put label and input for checkboxes/radios in a same line?

后端 未结 9 1775
一向
一向 2020-12-13 10:25

In my form I have some checkboxes, but by default, I have :

  • the first radio widget
  • the first label
  • the second radio widget
  • th
9条回答
  •  [愿得一人]
    2020-12-13 10:52

    You can overide the form_row function like that (modified to fit the temple label / checkbox of twitter bootstrap ) : (in that exemple it's "checkbox" but i think with "radio" it works the same)

    {% extends 'form_div_layout.html.twig' %}
    
    {% block field_row %}
    {% spaceless %}
        {% if 'checkbox' in types %}
            {% if not compound %}
                {% set label_attr = label_attr|merge({'for': id}) %}
            {% endif %}
            {% if required %}
                {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
            {% endif %}
            {% if label is empty %}
                {% set label = name|humanize %}
            {% endif %}
            
        {% else %}
            {{ parent() }}
        {% endif %}
    {% endspaceless %}
    {% endblock field_row %}
    

提交回复
热议问题