@@ -258,7 +258,7 @@ directly in the template that's actually rendering the form.
258
258
259
259
.. code-block :: html+twig
260
260
261
- {% extends ':: base.html.twig' %}
261
+ {% extends 'base.html.twig' %}
262
262
263
263
{% form_theme form _self %}
264
264
@@ -297,7 +297,7 @@ can now re-use the form customization across many templates:
297
297
298
298
.. code-block :: html+twig
299
299
300
- {# app/Resources/views/Form /fields.html.twig #}
300
+ {# app/Resources/views/form /fields.html.twig #}
301
301
{% block integer_widget %}
302
302
<div class="integer_widget">
303
303
{% set type = type|default('number') %}
@@ -313,7 +313,7 @@ tell Symfony to use the template via the ``form_theme`` tag:
313
313
314
314
.. code-block :: html+twig
315
315
316
- {% form_theme form 'AppBundle :Form: fields.html.twig' %}
316
+ {% form_theme form 'form/ fields.html.twig' %}
317
317
318
318
{{ form_widget(form.age) }}
319
319
@@ -329,13 +329,12 @@ name of all the templates as an array using the ``with`` keyword:
329
329
330
330
.. code-block :: html+twig
331
331
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'] %}
334
333
335
334
{# ... #}
336
335
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 `` .
339
338
340
339
Child Forms
341
340
...........
@@ -344,16 +343,16 @@ You can also apply a form theme to a specific child of your form:
344
343
345
344
.. code-block :: html+twig
346
345
347
- {% form_theme form.child 'AppBundle :Form: fields.html.twig' %}
346
+ {% form_theme form.child 'form/ fields.html.twig' %}
348
347
349
348
This is useful when you want to have a custom theme for a nested form that's
350
349
different than the one of your main form. Just specify both your themes:
351
350
352
351
.. code-block :: html+twig
353
352
354
- {% form_theme form 'AppBundle :Form: fields.html.twig' %}
353
+ {% form_theme form 'form/ fields.html.twig' %}
355
354
356
- {% form_theme form.child 'AppBundle :Form: fields_child.html.twig' %}
355
+ {% form_theme form.child 'form/ fields_child.html.twig' %}
357
356
358
357
.. _cookbook-form-php-theming :
359
358
@@ -369,9 +368,13 @@ file in order to customize the ``integer_widget`` fragment.
369
368
370
369
.. code-block :: html+php
371
370
372
- <!-- app/Resources/views/Form /integer_widget.html.php -->
371
+ <!-- app/Resources/views/form /integer_widget.html.php -->
373
372
<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
+ ) ?>
375
378
</div>
376
379
377
380
Now 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:
382
385
383
386
.. code-block :: php
384
387
385
- <?php $view['form']->setTheme($form, array('AppBundle:Form ')); ?>
388
+ <?php $view['form']->setTheme($form, array(':form ')); ?>
386
389
387
390
<?php $view['form']->widget($form['age']) ?>
388
391
@@ -395,7 +398,14 @@ method:
395
398
396
399
.. code-block :: php
397
400
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 ``.
399
409
400
410
.. _cookbook-form-twig-import-base-blocks :
401
411
469
479
~~~~
470
480
471
481
By 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.
474
484
475
485
.. configuration-block ::
476
486
@@ -479,14 +489,14 @@ form is rendered.
479
489
# app/config/config.yml
480
490
twig :
481
491
form_themes :
482
- - ' AppBundle:Form: fields.html.twig'
492
+ - 'form/ fields.html.twig'
483
493
# ...
484
494
485
495
.. code-block :: xml
486
496
487
497
<!-- app/config/config.xml -->
488
498
<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 >
490
500
<!-- ... -->
491
501
</twig : config >
492
502
@@ -495,7 +505,7 @@ form is rendered.
495
505
// app/config/config.php
496
506
$container->loadFromExtension('twig', array(
497
507
'form_themes' => array(
498
- 'AppBundle:Form: fields.html.twig',
508
+ 'form/ fields.html.twig',
499
509
),
500
510
501
511
// ...
@@ -671,7 +681,7 @@ customize the ``name`` field only:
671
681
.. code-block :: html+php
672
682
673
683
<!-- Main template -->
674
- <?php echo $view['form']->setTheme($form, array('AppBundle:Form ')); ?>
684
+ <?php echo $view['form']->setTheme($form, array(':form ')); ?>
675
685
676
686
<?php echo $view['form']->widget($form['name']); ?>
677
687
@@ -728,7 +738,7 @@ You can also override the markup for an entire field row using the same method:
728
738
.. code-block :: html+php
729
739
730
740
<!-- Main template -->
731
- <?php echo $view['form']->setTheme($form, array('AppBundle:Form ')); ?>
741
+ <?php echo $view['form']->setTheme($form, array(':form ')); ?>
732
742
733
743
<?php echo $view['form']->row($form['name']); ?>
734
744
0 commit comments