@@ -258,7 +258,7 @@ directly in the template that's actually rendering the form.
258258
259259.. code-block :: html+twig
260260
261- {% extends ':: base.html.twig' %}
261+ {% extends 'base.html.twig' %}
262262
263263 {% form_theme form _self %}
264264
@@ -297,7 +297,7 @@ can now re-use the form customization across many templates:
297297
298298.. code-block :: html+twig
299299
300- {# app/Resources/views/Form /fields.html.twig #}
300+ {# app/Resources/views/form /fields.html.twig #}
301301 {% block integer_widget %}
302302 <div class="integer_widget">
303303 {% set type = type|default('number') %}
@@ -313,7 +313,7 @@ tell Symfony to use the template via the ``form_theme`` tag:
313313
314314.. code-block :: html+twig
315315
316- {% form_theme form 'AppBundle :Form: fields.html.twig' %}
316+ {% form_theme form 'form/ fields.html.twig' %}
317317
318318 {{ form_widget(form.age) }}
319319
@@ -329,13 +329,12 @@ name of all the templates as an array using the ``with`` keyword:
329329
330330.. code-block :: html+twig
331331
332- {% form_theme form with ['::common.html.twig', ':Form: fields.html.twig',
333- 'AppBundle:Form: fields.html.twig'] %}
332+ {% form_theme form with ['common.html.twig', 'form/fields.html.twig'] %}
334333
335334 {# ... #}
336335
337- The templates can be located at different bundles and they can even be stored
338- at the global `` app/Resources/views/ `` directory .
336+ The templates can also be located in different bundles, use the functional name
337+ to reference these templates, e.g. `` AcmeFormExtraBundle:form:fields.html.twig `` .
339338
340339Child Forms
341340...........
@@ -344,16 +343,16 @@ You can also apply a form theme to a specific child of your form:
344343
345344.. code-block :: html+twig
346345
347- {% form_theme form.child 'AppBundle :Form: fields.html.twig' %}
346+ {% form_theme form.child 'form/ fields.html.twig' %}
348347
349348This is useful when you want to have a custom theme for a nested form that's
350349different than the one of your main form. Just specify both your themes:
351350
352351.. code-block :: html+twig
353352
354- {% form_theme form 'AppBundle :Form: fields.html.twig' %}
353+ {% form_theme form 'form/ fields.html.twig' %}
355354
356- {% form_theme form.child 'AppBundle :Form: fields_child.html.twig' %}
355+ {% form_theme form.child 'form/ fields_child.html.twig' %}
357356
358357.. _cookbook-form-php-theming :
359358
@@ -369,9 +368,13 @@ file in order to customize the ``integer_widget`` fragment.
369368
370369.. code-block :: html+php
371370
372- <!-- app/Resources/views/Form /integer_widget.html.php -->
371+ <!-- app/Resources/views/form /integer_widget.html.php -->
373372 <div class="integer_widget">
374- <?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "number")) ?>
373+ <?php echo $view['form']->block(
374+ $form,
375+ 'form_widget_simple',
376+ array('type' => isset($type) ? $type : "number")
377+ ) ?>
375378 </div>
376379
377380Now that you've created the customized form template, you need to tell Symfony
@@ -382,7 +385,7 @@ tell Symfony to use the theme via the ``setTheme`` helper method:
382385
383386.. code-block :: php
384387
385- <?php $view['form']->setTheme($form, array('AppBundle:Form ')); ?>
388+ <?php $view['form']->setTheme($form, array(':form ')); ?>
386389
387390 <?php $view['form']->widget($form['age']) ?>
388391
@@ -395,7 +398,14 @@ method:
395398
396399.. code-block :: php
397400
398- <?php $view['form']->setTheme($form['child'], 'AppBundle:Form/Child'); ?>
401+ <?php $view['form']->setTheme($form['child'], ':form'); ?>
402+
403+ .. note ::
404+
405+ The ``:form `` syntax is based on the functional names for templates:
406+ ``Bundle:Directory ``. As the form directory lives in the
407+ ``app/Resources/views `` directory, the ``Bundle `` part is empty, resulting
408+ in ``:form ``.
399409
400410.. _cookbook-form-twig-import-base-blocks :
401411
469479~~~~
470480
471481By using the following configuration, any customized form blocks inside the
472- ``AppBundle:Form: fields.html.twig `` template will be used globally when a
473- form is rendered.
482+ ``form/ fields.html.twig `` template will be used globally when a form is
483+ rendered.
474484
475485.. configuration-block ::
476486
@@ -479,14 +489,14 @@ form is rendered.
479489 # app/config/config.yml
480490 twig :
481491 form_themes :
482- - ' AppBundle:Form: fields.html.twig'
492+ - 'form/ fields.html.twig'
483493 # ...
484494
485495 .. code-block :: xml
486496
487497 <!-- app/config/config.xml -->
488498 <twig : config >
489- <twig : form-theme >AppBundle:Form: fields.html.twig</twig : form-theme >
499+ <twig : form-theme >form/ fields.html.twig</twig : form-theme >
490500 <!-- ... -->
491501 </twig : config >
492502
@@ -495,7 +505,7 @@ form is rendered.
495505 // app/config/config.php
496506 $container->loadFromExtension('twig', array(
497507 'form_themes' => array(
498- 'AppBundle:Form: fields.html.twig',
508+ 'form/ fields.html.twig',
499509 ),
500510
501511 // ...
@@ -671,7 +681,7 @@ customize the ``name`` field only:
671681 .. code-block :: html+php
672682
673683 <!-- Main template -->
674- <?php echo $view['form']->setTheme($form, array('AppBundle:Form ')); ?>
684+ <?php echo $view['form']->setTheme($form, array(':form ')); ?>
675685
676686 <?php echo $view['form']->widget($form['name']); ?>
677687
@@ -728,7 +738,7 @@ You can also override the markup for an entire field row using the same method:
728738 .. code-block :: html+php
729739
730740 <!-- Main template -->
731- <?php echo $view['form']->setTheme($form, array('AppBundle:Form ')); ?>
741+ <?php echo $view['form']->setTheme($form, array(':form ')); ?>
732742
733743 <?php echo $view['form']->row($form['name']); ?>
734744
0 commit comments