@@ -264,7 +264,7 @@ directly in the template that's actually rendering the form.
264
264
265
265
.. code-block :: html+twig
266
266
267
- {% extends ':: base.html.twig' %}
267
+ {% extends 'base.html.twig' %}
268
268
269
269
{% form_theme form _self %}
270
270
@@ -303,7 +303,7 @@ can now re-use the form customization across many templates:
303
303
304
304
.. code-block :: html+twig
305
305
306
- {# app/Resources/views/Form /fields.html.twig #}
306
+ {# app/Resources/views/form /fields.html.twig #}
307
307
{% block integer_widget %}
308
308
<div class="integer_widget">
309
309
{% set type = type|default('number') %}
@@ -319,7 +319,7 @@ tell Symfony to use the template via the ``form_theme`` tag:
319
319
320
320
.. code-block :: html+twig
321
321
322
- {% form_theme form 'AppBundle :Form: fields.html.twig' %}
322
+ {% form_theme form 'form/ fields.html.twig' %}
323
323
324
324
{{ form_widget(form.age) }}
325
325
@@ -335,13 +335,12 @@ name of all the templates as an array using the ``with`` keyword:
335
335
336
336
.. code-block :: html+twig
337
337
338
- {% form_theme form with ['::common.html.twig', ':Form: fields.html.twig',
339
- 'AppBundle:Form: fields.html.twig'] %}
338
+ {% form_theme form with ['common.html.twig', 'form/fields.html.twig'] %}
340
339
341
340
{# ... #}
342
341
343
- The templates can be located at different bundles and they can even be stored
344
- at the global `` app/Resources/views/ `` directory .
342
+ The templates can also be located in different bundles, use the functional name
343
+ to reference these templates, e.g. `` AcmeFormExtraBundle:form:fields.html.twig `` .
345
344
346
345
Child Forms
347
346
...........
@@ -350,16 +349,16 @@ You can also apply a form theme to a specific child of your form:
350
349
351
350
.. code-block :: html+twig
352
351
353
- {% form_theme form.child 'AppBundle :Form: fields.html.twig' %}
352
+ {% form_theme form.child 'form/ fields.html.twig' %}
354
353
355
354
This is useful when you want to have a custom theme for a nested form that's
356
355
different than the one of your main form. Just specify both your themes:
357
356
358
357
.. code-block :: html+twig
359
358
360
- {% form_theme form 'AppBundle :Form: fields.html.twig' %}
359
+ {% form_theme form 'form/ fields.html.twig' %}
361
360
362
- {% form_theme form.child 'AppBundle :Form: fields_child.html.twig' %}
361
+ {% form_theme form.child 'form/ fields_child.html.twig' %}
363
362
364
363
.. _cookbook-form-php-theming :
365
364
@@ -375,9 +374,13 @@ file in order to customize the ``integer_widget`` fragment.
375
374
376
375
.. code-block :: html+php
377
376
378
- <!-- app/Resources/views/Form /integer_widget.html.php -->
377
+ <!-- app/Resources/views/form /integer_widget.html.php -->
379
378
<div class="integer_widget">
380
- <?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "number")) ?>
379
+ <?php echo $view['form']->block(
380
+ $form,
381
+ 'form_widget_simple',
382
+ array('type' => isset($type) ? $type : "number")
383
+ ) ?>
381
384
</div>
382
385
383
386
Now that you've created the customized form template, you need to tell Symfony
@@ -388,7 +391,7 @@ tell Symfony to use the theme via the ``setTheme`` helper method:
388
391
389
392
.. code-block :: php
390
393
391
- <?php $view['form']->setTheme($form, array('AppBundle:Form ')); ?>
394
+ <?php $view['form']->setTheme($form, array(':form ')); ?>
392
395
393
396
<?php $view['form']->widget($form['age']) ?>
394
397
@@ -401,7 +404,14 @@ method:
401
404
402
405
.. code-block :: php
403
406
404
- <?php $view['form']->setTheme($form['child'], 'AppBundle:Form/Child'); ?>
407
+ <?php $view['form']->setTheme($form['child'], ':form'); ?>
408
+
409
+ .. note ::
410
+
411
+ The ``:form `` syntax is based on the functional names for templates:
412
+ ``Bundle:Directory ``. As the form directory lives in the
413
+ ``app/Resources/views `` directory, the ``Bundle `` part is empty, resulting
414
+ in ``:form ``.
405
415
406
416
.. _cookbook-form-twig-import-base-blocks :
407
417
475
485
~~~~
476
486
477
487
By using the following configuration, any customized form blocks inside the
478
- ``AppBundle:Form: fields.html.twig `` template will be used globally when a
479
- form is rendered.
488
+ ``form/ fields.html.twig `` template will be used globally when a form is
489
+ rendered.
480
490
481
491
.. configuration-block ::
482
492
@@ -485,14 +495,14 @@ form is rendered.
485
495
# app/config/config.yml
486
496
twig :
487
497
form_themes :
488
- - ' AppBundle:Form: fields.html.twig'
498
+ - 'form/ fields.html.twig'
489
499
# ...
490
500
491
501
.. code-block :: xml
492
502
493
503
<!-- app/config/config.xml -->
494
504
<twig : config >
495
- <twig : form-theme >AppBundle:Form: fields.html.twig</twig : form-theme >
505
+ <twig : form-theme >form/ fields.html.twig</twig : form-theme >
496
506
<!-- ... -->
497
507
</twig : config >
498
508
@@ -501,7 +511,7 @@ form is rendered.
501
511
// app/config/config.php
502
512
$container->loadFromExtension('twig', array(
503
513
'form_themes' => array(
504
- 'AppBundle:Form: fields.html.twig',
514
+ 'form/ fields.html.twig',
505
515
),
506
516
507
517
// ...
@@ -677,7 +687,7 @@ customize the ``name`` field only:
677
687
.. code-block :: html+php
678
688
679
689
<!-- Main template -->
680
- <?php echo $view['form']->setTheme($form, array('AppBundle:Form ')); ?>
690
+ <?php echo $view['form']->setTheme($form, array(':form ')); ?>
681
691
682
692
<?php echo $view['form']->widget($form['name']); ?>
683
693
@@ -735,7 +745,7 @@ You can also override the markup for an entire field row using the same method:
735
745
.. code-block :: html+php
736
746
737
747
<!-- Main template -->
738
- <?php echo $view['form']->setTheme($form, array('AppBundle:Form ')); ?>
748
+ <?php echo $view['form']->setTheme($form, array(':form ')); ?>
739
749
740
750
<?php echo $view['form']->row($form['name']); ?>
741
751
0 commit comments