Delete form-control class set in Form–How to set Form Themes [Symfony]

When I generated a Form with Symfony, I was worried that a Bootstrap class called “form-control” would be automatically added, so I investigated it.
From the result, it was because the Form Theme was set to bootstrap by default.

What is Form Themes?

Simply put, you can set up a template for the Form that Symfony will generate.
It is generated based on the set theme.

Setting location

# config/packages/twig.yaml

    form_themes: ['bootstrap_4_layout.html.twig']

You can change the theme by changing the settings of twig.yaml above.
The above example is an example when you want to use bootstrap4. The initial value is like this in recent versions.

Please refer to the official documentation to find out what themes are available.

How to Work with Form Themes

Basic theme without class

To prevent bootstrap’s “form-control” from being automatically defined as a class, as in my example, see below.

# config/packages/twig.yaml

        form_themes: ['form_div_layout.html.twig']

Also, if you want to set in twig units, you can set form_theme as shown below.

{# this form theme will be applied only to the form of this template #}
{% form_theme form 'bootstrap_5_layout.html.twig' %}


Looking at the official document, it seems that you can make quite detailed settings such as creating your own template.
Until now, if you want to use an html structure other than the form generated by Symfony, you have to embed the form data directly in the tag without using form_widget. It seems that making Form Theme will make it easier to use.

Leave a Reply 0

Your email address will not be published.

2 + 4 =