Skip to content

Commit 1d4b48f

Browse files
committed
Merge pull request #2998 from youbs/improve_form_customization
added docs about child forms customization
2 parents eda6157 + 628ad7f commit 1d4b48f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

cookbook/form/form_customization.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,24 @@ When the ``form.age`` widget is rendered, Symfony will use the ``integer_widget`
298298
block from the new template and the ``input`` tag will be wrapped in the
299299
``div`` element specified in the customized block.
300300

301+
Child Forms
302+
~~~~~~~~~~~
303+
304+
You can apply a form theme to a specific child of your form:
305+
306+
.. code-block:: html+jinja
307+
308+
{% form_theme form.child 'AcmeDemoBundle:Form:fields.html.twig' %}
309+
310+
This is useful when you want to have a custom theme for a nested form different
311+
than the one of your main form. Just specify both your themes:
312+
313+
.. code-block:: html+jinja
314+
315+
{% form_theme form 'AcmeDemoBundle:Form:fields.html.twig' %}
316+
317+
{% form_theme form.child 'AcmeDemoBundle:Form:fields_child.html.twig' %}
318+
301319
.. _cookbook-form-php-theming:
302320

303321
Form Theming in PHP
@@ -333,6 +351,13 @@ When the ``form.age`` widget is rendered, Symfony will use the customized
333351
``integer_widget.html.php`` template and the ``input`` tag will be wrapped in
334352
the ``div`` element.
335353

354+
If you want to apply a theme to a specific child form, pass it to the ``setTheme``
355+
method:
356+
357+
.. code-block:: php
358+
359+
<?php $view['form']->setTheme($form['child'], 'AcmeDemoBundle:Form/Child'); ?>
360+
336361
.. _cookbook-form-twig-import-base-blocks:
337362

338363
Referencing Base Form Blocks (Twig specific)

0 commit comments

Comments
 (0)