How can I display a separate field (one field for a radio / flag) in Twig in Symfony 2.6?
Say I have a simple form:
class TransportType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('transport', 'choice', array( 'choices' => array( 'road' => 'Car/bus', 'train' => 'Train', ), 'expanded' => true, 'multiple' => false )); }
In previous versions of Symfony2, I could just use:
{{ form_widget(form.transport.road) }} {{ form_widget(form.transport.train) }}
to display individual switches, but it no longer works. I know I can use:
{{ form_widget(form.transport[0]) }} {{ form_widget(form.transport[1]) }}
but it is less flexible. Of course, I can iterate over the collection and check the name, but this seems like unnecessary trouble. Is there an easier way?
I tried offsetGet (which should be return a child by name ), but it also only works with array index.
php symfony twig symfony-forms
grzechoo
source share