Symfony 6 Certification New exam with updated questions 100% online Show your expertise

New in Symfony 3.4: Disable global form themes

Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.

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:

# app/config/config.yml
    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:

{% 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.

Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.


Beautiful! I always stayed away from global themes for this particual reason.

Thanks a lot!

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.