How to display select boxes one at a time

How can I display select boxes one at a time using Twig?

I have this field to create radio buttons:

...
->add('types', 'choice', array(
                    'choices' => array(
                        'c1' => '1',
                        'c2' => '2',
                        'c3' => '3',
                        'c4' => '4'
                    ),
...

      

and that does the radio buttons, but I want to display one by one because the radio buttons are inline ...

With Twig, I do with: {{ form_widget(form.types) }}

or {{ form_row(form.types) }}

, but do the same ...

+3


source to share


1 answer


You can display them one by one with this in your Twig:

{% for type in form.types %}
    {{ form_row(type) }}
{% endfor %}

      

You can even split the rendering (as described in the doc here ) to adapt it to what you want:



{% for type in form.types %}
    {{ form_label(type) }}
    {{ form_widget(type) }}
    {{ form_error(type) }}
{% endfor %}

      

After that, you just need to look at what's generated and adapt your code to include newlines wherever you need them.

+3


source







All Articles