@@ -344,53 +344,10 @@ different than the one of your main form. Just specify both your themes:
344344
345345 {% form_theme form.a_child_form 'form/fields_child.html.twig' %}
346346
347- Form Theming in PHP
348- -------------------
347+ .. _referencing-base-form-blocks-twig-specific :
349348
350- When using PHP as a templating engine, the only method to customize a fragment
351- is to create a new template file - this is similar to the second method used by
352- Twig.
353-
354- The template file must be named after the fragment. You must create a ``integer_widget.html.php ``
355- file in order to customize the ``integer_widget `` fragment.
356-
357- ..code-block ::html+php
358-
359- <!-- src/Resources/integer_widget.html.php -->
360- <div class="integer_widget">
361- <?php echo $view['form']->block(
362- $form,
363- 'form_widget_simple',
364- array('type' => isset($type) ? $type : "number")
365- ) ?>
366- </div>
367-
368- Now that you've created the customized form template, you need to tell Symfony
369- to use it. Inside the template where you're actually rendering your form,
370- tell Symfony to use the theme via the ``setTheme() `` helper method::
371-
372- <?php $view['form']->setTheme($form, array(':form')); ?>
373-
374- <?php $view['form']->widget($form['age']) ?>
375-
376- When the ``form.age `` widget is rendered, Symfony will use the customized
377- ``integer_widget.html.php `` template and the ``input `` tag will be wrapped in
378- the ``div `` element.
379-
380- If you want to apply a theme to a specific child form, pass it to the ``setTheme() ``
381- method::
382-
383- <?php $view['form']->setTheme($form['child'], ':form'); ?>
384-
385- ..note ::
386-
387- The ``:form `` syntax is based on the functional names for templates:
388- ``Bundle:Directory ``. As the form directory lives in the
389- ``templates/ `` directory, the ``Bundle `` part is empty, resulting
390- in ``:form ``.
391-
392- Referencing base Form Blocks (Twig specific)
393- --------------------------------------------
349+ Referencing base Form Blocks
350+ ----------------------------
394351
395352So far, to override a particular form block, the best method is to copy
396353the default block from `form_div_layout.html.twig `_, paste it into a different template,
@@ -446,16 +403,15 @@ the base block by using the ``parent()`` Twig function:
446403 templating engine. You have to manually copy the content from the base block
447404 to your new template file.
448405
406+ .. _twig :
407+
449408Making Application-wide Customizations
450409--------------------------------------
451410
452411If you'd like a certain form customization to be global to your application,
453412you can accomplish this by making the form customizations in an external
454413template and then importing it inside your application configuration.
455414
456- Twig
457- ~~~~
458-
459415By using the following configuration, any customized form blocks inside the
460416``form/fields.html.twig `` template will be used globally when a form is
461417rendered.
@@ -552,125 +508,6 @@ your template file rather than adding the template as a resource:
552508Note that the ``form `` variable in the above code is the form view variable
553509that you passed to your template.
554510
555- PHP
556- ~~~
557-
558- By using the following configuration, any customized form fragments inside the
559- ``templates/form `` folder will be used globally when a
560- form is rendered.
561-
562- ..configuration-block ::
563-
564- ..code-block ::yaml
565-
566- # config/packages/framework.yaml
567- framework :
568- templating :
569- form :
570- resources :
571- -' App:Form'
572- # ...
573-
574- ..code-block ::xml
575-
576- <!-- config/packages/framework.xml-->
577- <?xml version =" 1.0" encoding =" UTF-8" ?>
578- <container xmlns =" http://symfony.com/schema/dic/services"
579- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
580- xmlns : framework =" http://symfony.com/schema/dic/symfony"
581- xsi : schemaLocation =" http://symfony.com/schema/dic/services
582- http://symfony.com/schema/dic/services/services-1.0.xsd
583- http://symfony.com/schema/dic/symfony
584- http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
585-
586- <framework : config >
587- <framework : templating >
588- <framework : form >
589- <framework : resource >App:Form</framework : resource >
590- </framework : form >
591- </framework : templating >
592- <!-- ...-->
593- </framework : config >
594- </container >
595-
596- ..code-block ::php
597-
598- // config/packages/framework.php
599- // PHP
600- $container->loadFromExtension('framework', array(
601- 'templating' => array(
602- 'form' => array(
603- 'resources' => array(
604- 'App:Form',
605- ),
606- ),
607- ),
608-
609- // ...
610- ));
611-
612- By default, the PHP engine uses a *div * layout when rendering forms. Some people,
613- however, may prefer to render forms in a *table * layout. Use the ``FrameworkBundle:FormTable ``
614- resource to use such a layout:
615-
616- ..configuration-block ::
617-
618- ..code-block ::yaml
619-
620- # config/packages/framework.yaml
621- framework :
622- templating :
623- form :
624- resources :
625- -' FrameworkBundle:FormTable'
626-
627- ..code-block ::xml
628-
629- <!-- config/packages/framework.xml-->
630- <?xml version =" 1.0" encoding =" UTF-8" ?>
631- <container xmlns =" http://symfony.com/schema/dic/services"
632- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
633- xmlns : framework =" http://symfony.com/schema/dic/symfony"
634- xsi : schemaLocation =" http://symfony.com/schema/dic/services
635- http://symfony.com/schema/dic/services/services-1.0.xsd
636- http://symfony.com/schema/dic/symfony
637- http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
638-
639- <framework : config >
640- <framework : templating >
641- <framework : form >
642- <resource >FrameworkBundle:FormTable</resource >
643- </framework : form >
644- </framework : templating >
645- <!-- ...-->
646- </framework : config >
647- </container >
648-
649- ..code-block ::php
650-
651- // config/packages/framework.php
652- $container->loadFromExtension('framework', array(
653- 'templating' => array(
654- 'form' => array(
655- 'resources' => array(
656- 'FrameworkBundle:FormTable',
657- ),
658- ),
659- ),
660-
661- // ...
662- ));
663-
664- If you only want to make the change in one template, add the following line to
665- your template file rather than adding the template as a resource:
666-
667- ..code-block ::html+php
668-
669- <?php $view['form']->setTheme($form, array('FrameworkBundle:FormTable')); ?>
670-
671- Note that the ``$form `` variable in the above code is the form view variable
672- that you passed to your template.
673-
674511How to Customize an individual Field
675512------------------------------------
676513
@@ -908,7 +745,7 @@ Adding a "Required" Asterisk to Field Labels
908745If you want to denote all of your required fields with a required asterisk (``* ``),
909746you can do this by customizing the ``form_label `` fragment.
910747
911- In Twig, if you're making the form customization inside the same template as your
748+ If you're making the form customization inside the same template as your
912749form, modify the ``use `` tag and add the following:
913750
914751..code-block ::html+twig
@@ -923,7 +760,7 @@ form, modify the ``use`` tag and add the following:
923760 {% endif %}
924761 {% endblock %}
925762
926- In Twig, if you're making the form customization inside a separate template, use
763+ If you're making the form customization inside a separate template, use
927764the following:
928765
929766..code-block ::html+twig
@@ -938,24 +775,6 @@ the following:
938775 {% endif %}
939776 {% endblock %}
940777
941- When using PHP as a templating engine you have to copy the content from the
942- original template:
943-
944- ..code-block ::html+php
945-
946- <!-- form_label.html.php -->
947-
948- <!-- original content -->
949- <?php if ($required) { $label_attr['class'] = trim((isset($label_attr['class']) ? $label_attr['class'] : '').' required'); } ?>
950- <?php if (!$compound) { $label_attr['for'] = $id; } ?>
951- <?php if (!$label) { $label = $view['form']->humanize($name); } ?>
952- <label <?php foreach ($label_attr as $k => $v) { printf('%s="%s" ', $view->escape($k), $view->escape($v)); } ?>><?php echo $view->escape($view['translator']->trans($label, array(), $translation_domain)) ?></label>
953-
954- <!-- customization -->
955- <?php if ($required) : ?>
956- <span class="required" title="This field is required">*</span>
957- <?php endif ?>
958-
959778..tip ::
960779
961780 See:ref: `form-theming-methods ` for how to apply this customization.
@@ -976,7 +795,7 @@ Adding "help" Messages
976795
977796You can also customize your form widgets to have an optional "help" message.
978797
979- In Twig, if you're making the form customization inside the same template as your
798+ If you're making the form customization inside the same template as your
980799form, modify the ``use `` tag and add the following:
981800
982801..code-block ::html+twig
@@ -991,7 +810,7 @@ form, modify the ``use`` tag and add the following:
991810 {% endif %}
992811 {% endblock %}
993812
994- In Twig, if you're making the form customization inside a separate template, use
813+ If you're making the form customization inside a separate template, use
995814the following:
996815
997816..code-block ::html+twig
@@ -1006,25 +825,6 @@ the following:
1006825 {% endif %}
1007826 {% endblock %}
1008827
1009- When using PHP as a templating engine you have to copy the content from the
1010- original template:
1011-
1012- ..code-block ::html+php
1013-
1014- <!-- form_widget_simple.html.php -->
1015-
1016- <!-- Original content -->
1017- <input
1018- type="<?php echo isset($type) ? $view->escape($type) : 'text' ?>"
1019- <?php if (!empty($value)): ?>value="<?php echo $view->escape($value) ?>"<?php endif ?>
1020- <?php echo $view['form']->block($form, 'widget_attributes') ?>
1021- />
1022-
1023- <!-- Customization -->
1024- <?php if (isset($help)) : ?>
1025- <span class="help"><?php echo $view->escape($help) ?></span>
1026- <?php endif ?>
1027-
1028828To render a help message below a field, pass in a ``help `` variable:
1029829
1030830..code-block ::twig