Search code examples
phpsymfonymaterialize

Render input before label with Twig or form builder


I'm using materialize for the front end and I have an issue with the rendering of checkbox, to make the materialize checkbox works I've to put the label after the input but I build the form with symfony so this puts the label before the input. Here is how I build my form :

$builder
->add('libelle')
->add('ordre')
->add('categorie')
    ->add('type', ChoiceType::class, array(
        'choices'  => array(
            'Commande' => 'commande',
            'Produit' => 'produit',
            'Face'      => 'face',
            'Job'       => 'job'
        )
    ))
    ->add('fin', CheckboxType::class, array(
        'label'    => 'Fin action'
    ));

And I render the form like this :

{{ form_start(edit_form, {'attr': {'class': 'full'}}) }}
  {{ form_widget(edit_form) }}
{{ form_end(edit_form) }}

Is there a way with the form builder or twig to render the label after the input ?


Solution

  • You can output label and field separately in Twig:

    {{ form_label(field_name) }}
    {{ form_widget(field_name) }}