Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages in full color showing how to combine Symfony with Docker, APIs, queues & async tasks, Webpack, Single-Page Applications, etc.

Buy printed version

New in Symfony 3.4: Disable global form themes

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.


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.