New in Symfony 3.4: Disable global form themes
October 18, 2017 • Published by Javier Eguiluz
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
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.
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.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
Thanks a lot!