Symfony2 how to render Checkboxes?

前端 未结 3 562
醉话见心
醉话见心 2021-01-03 10:18

I have a formbuilder form with a multiple choice list of countries. When I render them on my form like this:

{{ form_widget(edit_form.countries) }}
<         


        
3条回答
  •  天命终不由人
    2021-01-03 10:58

    A lazier way I found to do this was to iterate through the form/choice array.

    At its simplest, rendering a form you might do:

    {{ form_widget(form) }}
    

    For a little more granularity, you might do:

    {{ form_row(form.itemA) }}
    {{ form_row(form.itemB) }}
    {{ form_row(form.itemC) }}
    

    But if "itemA" is a multi-choice, you're stuck with the entire list getting rendered on the same line. If you're looking for just a little more granularity before you step up to theming, you can do this:

    {% for t in form.itemA %}
    {{ form_row(t) }}
    {% endfor %}
    

    That'll render each checkbox on its own line, or give you an opportunity to do whatever you want between each item.

提交回复
热议问题