Edi Modrić
Contributed by Edi Modrić in #22610

Symfony Forms let you apply one or more themes globally to all the forms of your application. For example, just by adding this config, your forms will be beautifully formatted for Bootstrap 4:

1
2
3
# app/config/config.yml
twig:
    form_themes: ['bootstrap_4_layout.html.twig']

However, global themes provide little flexibility because they are applied unconditionally. That's why in Symfony 3.4 we improved the form_theme Twig tag to let you disable global form themes.

If you want a specific form to not use the global themes, define its themes with the form_theme Twig tag and add the only keyword at the end of it:

1
2
3
{% form_theme form with ['common.html.twig', 'form/fields.html.twig'] only %}

{# ... #}

Beware that the only keyword makes Symfony not use any of the global themes, including the form_div_layout.html.twig base theme. Make sure that your custom themes provide all the needed blocks and features or make them extend the base theme with the use Twig tag to reuse the original contents.

Published in #Living on the edge