Skip to content

Commit e34e6c2

Browse files
committed
feature #8495 [Form] Document disabling the usage of globally defined form themes (emodric, javiereguiluz)
This PR was merged into the 3.4 branch. Discussion ---------- [Form] Document disabling the usage of globally defined form themes This PR documents the option to disable the usage of globally defined form themes. This is suggested as a feature in symfony/symfony#22610 (reviewed, but not yet merged) Commits ------- 14ef7ae Minor reword 8d45f83 Document disabling the usage of globally defined form themes
2 parents 4cc445c + 14ef7ae commit e34e6c2

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

form/form_customization.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,38 @@ name of all the templates as an array using the ``with`` keyword:
343343
The templates can also be located in different bundles, use the Twig namespaced
344344
path to reference these templates, e.g. ``@AcmeFormExtra/form/fields.html.twig``.
345345

346+
Disabling usage of globally defined themes
347+
..........................................
348+
349+
Sometimes it is useful to disable usage of globally defined form themes in order
350+
to have more control over rendering of a form. You might want this, for example,
351+
when creating admin interface for a bundle which can be installed on a wide range
352+
of Symfony apps and you can't control what themes are defined globally.
353+
354+
You can do this by including the ``only`` keyword after the list of used form
355+
themes:
356+
357+
.. code-block:: html+twig
358+
359+
{% form_theme form with ['common.html.twig', 'form/fields.html.twig'] only %}
360+
361+
{# ... #}
362+
363+
.. caution::
364+
365+
When using the ``only`` keyword, none of Symfony's built-in form themes
366+
(``form_div_layout.html.twig``, etc.) will be applied. In order to render
367+
your forms correctly, you need to either provide a full-featured form theme
368+
yourself, or extend one of the built-in form themes with Twig's ``use``
369+
keyword instead of ``extends`` to reuse the original theme contents.
370+
371+
.. code-block:: html+twig
372+
373+
{# app/Resources/views/common.html.twig #}
374+
{% use "form_div_layout.html.twig" %}
375+
376+
{# ... #}
377+
346378
Child Forms
347379
...........
348380

0 commit comments

Comments
 (0)