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

后端 未结 9 1801
一向
一向 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:50

    In Symfony 2.4, this doesn't work quite as expected.

    {% block checkbox_widget %}
    {% spaceless %}
      
    {% endspaceless %}
    {% endblock checkbox_widget %}
    

    ...the label is not available. You need to add the following:

    {% if label is empty %}
      {% set label = name|humanize %}
    {% endif %}
    

    So a complete solution is:

    {% block checkbox_widget %}
    {% if label is empty %}
      {% set label = name|humanize %}
    {% endif %}
    {% spaceless %}
      
    {% endspaceless %}
    {% endblock checkbox_widget %}
    

提交回复
热议问题