@@ -243,7 +243,7 @@ directly in the template that's actually rendering the form.
243243
244244.. code-block :: html+twig
245245
246- {% extends ':: base.html.twig' %}
246+ {% extends 'base.html.twig' %}
247247
248248 {% form_theme form _self %}
249249
@@ -282,7 +282,7 @@ can now re-use the form customization across many templates:
282282
283283.. code-block :: html+twig
284284
285- {# src/AppBundle/ Resources/views/Form /fields.html.twig #}
285+ {# app/ Resources/views/form /fields.html.twig #}
286286 {% block integer_widget %}
287287 <div class="integer_widget">
288288 {% set type = type|default('number') %}
@@ -298,7 +298,7 @@ tell Symfony to use the template via the ``form_theme`` tag:
298298
299299.. code-block :: html+twig
300300
301- {% form_theme form 'AppBundle :Form: fields.html.twig' %}
301+ {% form_theme form 'form/ fields.html.twig' %}
302302
303303 {{ form_widget(form.age) }}
304304
@@ -314,13 +314,12 @@ name of all the templates as an array using the ``with`` keyword:
314314
315315.. code-block :: html+twig
316316
317- {% form_theme form with ['::common.html.twig', ':Form: fields.html.twig',
318- 'AppBundle:Form: fields.html.twig'] %}
317+ {% form_theme form with ['common.html.twig', 'form/fields.html.twig'] %}
319318
320319 {# ... #}
321320
322- The templates can be located at different bundles and they can even be stored
323- at the global `` app/Resources/views/ `` directory .
321+ The templates can also be located in different bundles, use the functional name
322+ to reference these templates, e.g. `` AcmeFormExtraBundle:form:fields.html.twig `` .
324323
325324Child Forms
326325...........
@@ -329,16 +328,16 @@ You can also apply a form theme to a specific child of your form:
329328
330329.. code-block :: html+twig
331330
332- {% form_theme form.child 'AppBundle :Form: fields.html.twig' %}
331+ {% form_theme form.child 'form/ fields.html.twig' %}
333332
334333This is useful when you want to have a custom theme for a nested form that's
335334different than the one of your main form. Just specify both your themes:
336335
337336.. code-block :: html+twig
338337
339- {% form_theme form 'AppBundle :Form: fields.html.twig' %}
338+ {% form_theme form 'form/ fields.html.twig' %}
340339
341- {% form_theme form.child 'AppBundle :Form: fields_child.html.twig' %}
340+ {% form_theme form.child 'form/ fields_child.html.twig' %}
342341
343342.. _cookbook-form-php-theming :
344343
@@ -354,9 +353,13 @@ file in order to customize the ``integer_widget`` fragment.
354353
355354.. code-block :: html+php
356355
357- <!-- app/Resources/views/Form /integer_widget.html.php -->
356+ <!-- app/Resources/views/form /integer_widget.html.php -->
358357 <div class="integer_widget">
359- <?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "number")) ?>
358+ <?php echo $view['form']->block(
359+ $form,
360+ 'form_widget_simple',
361+ array('type' => isset($type) ? $type : "number")
362+ ) ?>
360363 </div>
361364
362365Now that you've created the customized form template, you need to tell Symfony
@@ -367,7 +370,7 @@ tell Symfony to use the theme via the ``setTheme`` helper method:
367370
368371.. code-block :: php
369372
370- <?php $view['form']->setTheme($form, array('AppBundle:Form ')); ?>
373+ <?php $view['form']->setTheme($form, array(':form ')); ?>
371374
372375 <?php $view['form']->widget($form['age']) ?>
373376
@@ -380,7 +383,14 @@ method:
380383
381384.. code-block :: php
382385
383- <?php $view['form']->setTheme($form['child'], 'AppBundle:Form/Child'); ?>
386+ <?php $view['form']->setTheme($form['child'], ':form'); ?>
387+
388+ .. note ::
389+
390+ The ``:form `` syntax is based on the functional names for templates:
391+ ``Bundle:Directory ``. As the form directory lives in the
392+ ``app/Resources/views `` directory, the ``Bundle `` part is empty, resulting
393+ in ``:form ``.
384394
385395.. _cookbook-form-twig-import-base-blocks :
386396
454464~~~~
455465
456466By using the following configuration, any customized form blocks inside the
457- ``AppBundle:Form: fields.html.twig `` template will be used globally when a
458- form is rendered.
467+ ``form/ fields.html.twig `` template will be used globally when a form is
468+ rendered.
459469
460470.. configuration-block ::
461471
@@ -465,15 +475,15 @@ form is rendered.
465475 twig :
466476 form :
467477 resources :
468- - ' AppBundle:Form: fields.html.twig'
478+ - ' form/ fields.html.twig'
469479 # ...
470480
471481 .. code-block :: xml
472482
473483 <!-- app/config/config.xml -->
474484 <twig : config >
475485 <twig : form >
476- <resource >AppBundle:Form: fields.html.twig</resource >
486+ <resource >form/ fields.html.twig</resource >
477487 </twig : form >
478488 <!-- ... -->
479489 </twig : config >
@@ -484,7 +494,7 @@ form is rendered.
484494 $container->loadFromExtension('twig', array(
485495 'form' => array(
486496 'resources' => array(
487- 'AppBundle:Form: fields.html.twig',
497+ 'form/ fields.html.twig',
488498 ),
489499 ),
490500
@@ -666,7 +676,7 @@ customize the ``name`` field only:
666676 .. code-block :: html+php
667677
668678 <!-- Main template -->
669- <?php echo $view['form']->setTheme($form, array('AppBundle:Form ')); ?>
679+ <?php echo $view['form']->setTheme($form, array(':form ')); ?>
670680
671681 <?php echo $view['form']->widget($form['name']); ?>
672682
@@ -723,7 +733,7 @@ You can also override the markup for an entire field row using the same method:
723733 .. code-block :: html+php
724734
725735 <!-- Main template -->
726- <?php echo $view['form']->setTheme($form, array('AppBundle:Form ')); ?>
736+ <?php echo $view['form']->setTheme($form, array(':form ')); ?>
727737
728738 <?php echo $view['form']->row($form['name']); ?>
729739
0 commit comments