Skip to content

Commit 8d45f83

Browse files
committed
Document disabling the usage of globally defined form themes
1 parent 7bb20ba commit 8d45f83

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

form/form_customization.rst

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

339+
Disabling usage of globally defined themes
340+
..........................................
341+
342+
Sometimes it is useful to disable usage of globally defined form themes in order
343+
to have more control over rendering of a form. You might want this, for example,
344+
when creating admin interface for a bundle which can be installed on a wide range
345+
of Symfony apps and you can't control what themes are defined globally.
346+
347+
You can do this by including the ``only`` keyword after the list of used form
348+
themes:
349+
350+
.. code-block:: html+twig
351+
352+
{% form_theme form with ['common.html.twig', 'form/fields.html.twig'] only %}
353+
354+
{# ... #}
355+
356+
.. caution::
357+
358+
When using the ``only`` keyword, form themes shipped with Symfony
359+
(``form_div_layout.html.twig`` and others) will not be used, so to render your
360+
forms correcly, you need to either provide the base form theme yourself, or
361+
``use`` one of the built in form themes from your own theme:
362+
363+
.. code-block:: html+twig
364+
365+
{# app/Resources/views/common.html.twig #}
366+
{% use "form_div_layout.html.twig" %}
367+
368+
{# ... #}
369+
339370
Child Forms
340371
...........
341372

0 commit comments

Comments
 (0)