@@ -243,7 +243,7 @@ directly in the template that's actually rendering the form.
243
243
244
244
.. code-block :: html+twig
245
245
246
- {% extends ':: base.html.twig' %}
246
+ {% extends 'base.html.twig' %}
247
247
248
248
{% form_theme form _self %}
249
249
@@ -282,7 +282,7 @@ can now re-use the form customization across many templates:
282
282
283
283
.. code-block :: html+twig
284
284
285
- {# src/AppBundle/ Resources/views/Form /fields.html.twig #}
285
+ {# app/ Resources/views/form /fields.html.twig #}
286
286
{% block integer_widget %}
287
287
<div class="integer_widget">
288
288
{% set type = type|default('number') %}
@@ -298,7 +298,7 @@ tell Symfony to use the template via the ``form_theme`` tag:
298
298
299
299
.. code-block :: html+twig
300
300
301
- {% form_theme form 'AppBundle :Form: fields.html.twig' %}
301
+ {% form_theme form 'form/ fields.html.twig' %}
302
302
303
303
{{ form_widget(form.age) }}
304
304
@@ -314,13 +314,12 @@ name of all the templates as an array using the ``with`` keyword:
314
314
315
315
.. code-block :: html+twig
316
316
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'] %}
319
318
320
319
{# ... #}
321
320
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 `` .
324
323
325
324
Child Forms
326
325
...........
@@ -329,16 +328,16 @@ You can also apply a form theme to a specific child of your form:
329
328
330
329
.. code-block :: html+twig
331
330
332
- {% form_theme form.child 'AppBundle :Form: fields.html.twig' %}
331
+ {% form_theme form.child 'form/ fields.html.twig' %}
333
332
334
333
This is useful when you want to have a custom theme for a nested form that's
335
334
different than the one of your main form. Just specify both your themes:
336
335
337
336
.. code-block :: html+twig
338
337
339
- {% form_theme form 'AppBundle :Form: fields.html.twig' %}
338
+ {% form_theme form 'form/ fields.html.twig' %}
340
339
341
- {% form_theme form.child 'AppBundle :Form: fields_child.html.twig' %}
340
+ {% form_theme form.child 'form/ fields_child.html.twig' %}
342
341
343
342
.. _cookbook-form-php-theming :
344
343
@@ -354,9 +353,13 @@ file in order to customize the ``integer_widget`` fragment.
354
353
355
354
.. code-block :: html+php
356
355
357
- <!-- app/Resources/views/Form /integer_widget.html.php -->
356
+ <!-- app/Resources/views/form /integer_widget.html.php -->
358
357
<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
+ ) ?>
360
363
</div>
361
364
362
365
Now 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:
367
370
368
371
.. code-block :: php
369
372
370
- <?php $view['form']->setTheme($form, array('AppBundle:Form ')); ?>
373
+ <?php $view['form']->setTheme($form, array(':form ')); ?>
371
374
372
375
<?php $view['form']->widget($form['age']) ?>
373
376
@@ -380,7 +383,14 @@ method:
380
383
381
384
.. code-block :: php
382
385
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 ``.
384
394
385
395
.. _cookbook-form-twig-import-base-blocks :
386
396
454
464
~~~~
455
465
456
466
By 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.
459
469
460
470
.. configuration-block ::
461
471
@@ -465,15 +475,15 @@ form is rendered.
465
475
twig :
466
476
form :
467
477
resources :
468
- - ' AppBundle:Form: fields.html.twig'
478
+ - ' form/ fields.html.twig'
469
479
# ...
470
480
471
481
.. code-block :: xml
472
482
473
483
<!-- app/config/config.xml -->
474
484
<twig : config >
475
485
<twig : form >
476
- <resource >AppBundle:Form: fields.html.twig</resource >
486
+ <resource >form/ fields.html.twig</resource >
477
487
</twig : form >
478
488
<!-- ... -->
479
489
</twig : config >
@@ -484,7 +494,7 @@ form is rendered.
484
494
$container->loadFromExtension('twig', array(
485
495
'form' => array(
486
496
'resources' => array(
487
- 'AppBundle:Form: fields.html.twig',
497
+ 'form/ fields.html.twig',
488
498
),
489
499
),
490
500
@@ -666,7 +676,7 @@ customize the ``name`` field only:
666
676
.. code-block :: html+php
667
677
668
678
<!-- Main template -->
669
- <?php echo $view['form']->setTheme($form, array('AppBundle:Form ')); ?>
679
+ <?php echo $view['form']->setTheme($form, array(':form ')); ?>
670
680
671
681
<?php echo $view['form']->widget($form['name']); ?>
672
682
@@ -723,7 +733,7 @@ You can also override the markup for an entire field row using the same method:
723
733
.. code-block :: html+php
724
734
725
735
<!-- Main template -->
726
- <?php echo $view['form']->setTheme($form, array('AppBundle:Form ')); ?>
736
+ <?php echo $view['form']->setTheme($form, array(':form ')); ?>
727
737
728
738
<?php echo $view['form']->row($form['name']); ?>
729
739
0 commit comments