diff --git a/guides/forms/index.rst b/guides/forms/index.rst
index 2b608d8a05d..b4bc46c9753 100644
--- a/guides/forms/index.rst
+++ b/guides/forms/index.rst
@@ -6,4 +6,3 @@ Symfony2 Forms
overview
view
- twig
diff --git a/guides/forms/twig.rst b/guides/forms/twig.rst
deleted file mode 100644
index 40cccb6d877..00000000000
--- a/guides/forms/twig.rst
+++ /dev/null
@@ -1,366 +0,0 @@
-.. index::
- pair: Forms; Twig
-
-Forms in Twig Templates
-=======================
-
-A Symfony2 :doc:`Form ` is made of fields. Fields
-describe the form semantic, not its end-user representation; it means that a
-form is not necessarily tied to HTML. Instead, it is the responsibility of the
-web designer to display each form field the way he wants. So, displaying a
-Symfony2 form in a template can easily be done manually. But, Twig eases form
-integration and customization by providing a set of filters that can be applied
-on the form and field instances.
-
-Displaying a Form "manually"
-----------------------------
-
-Before diving into the Twig filters and how they help you display form easily,
-securely, and fast, you must know that nothing special happens under the hood.
-You can use any HTML you want to display a Symfony2 form:
-
-.. code-block:: html
-
-
-
-If there is a validation error, you should display it and fill the fields with
-the submitted values to make it easier to fix the problems fast. Just use the
-form dedicated methods:
-
-.. code-block:: jinja
-
-
-
-The Twig filters help you to keep your template short, make your form layout
-easily customizable, support internationalization, CSRF protection, file
-upload, and more out of the box. The following sections tells you everything
-about them.
-
-Displaying a Form
------------------
-
-As the global structure of a form (the form tag, the submit button, ...) is
-not defined by the form instance, you are free to use the HTML code you want.
-A simple form template reads as follows:
-
-.. code-block:: html
-
-
-
-Besides the global form structure, you need a way to display global errors and
-hidden fields; that's the job of the ``render_errors`` and ``render_hidden``
-filters respectively:
-
-.. code-block:: jinja
-
-
-
-.. note::
- By default, the ``render_errors`` generates a ``
`` list, but this can
- be easily customized as you will see later in this document.
-
-Last but not the least, a form containing a file input must contain the
-``enctype`` attribute; use the ``render_enctype`` filter to render it:
-
-.. code-block:: jinja
-
-
Besides the global form structure, you need a way to display global errors and
-hidden fields; that's the job of the ``errors()`` and ``hidden()`` methods
-respectively:
-
-.. code-block:: html+php
-
-
- errors() ?>
-
-
-
- hidden() ?>
-
-
-
-
+hidden fields. Symfony2 provides helpers to fulfill this job. In Twig templates,
+these helpers are implemented as global filters that can be applied on forms
+and form fields. In PHP templates, the "form" helper offers the same
+functionality through public methods that accept the form or form field as
+parameter.
+
+.. configuration-block::
+
+ .. code-block:: jinja
+
+
+
.. note::
- By default, the ``errors()`` method generates a ``
`` list, but this
+ As you can see, Twig filters are prefixed with "render_". Other than the
+ methods of the "form" helper, these filters are global and prone to
+ naming collisions.
+
+.. tip::
+ By default, the ``errors`` helper generates a ``
`` list, but this
can be easily customized as you will see later in this document.
Last but not the least, a form containing a file input must contain the
-``enctype`` attribute; use the ``form()`` method to take care of it:
-
-.. code-block:: html+php
-
- form('#') ?>
-
+``enctype`` attribute; use the ``enctype`` helper to take render it:
+
+.. configuration-block::
+
+ .. code-block:: jinja
+
+
+
+ .. code-block:: html+php
+
+
enctype($form) ?> method="post">
+
Displaying Fields
-----------------
Accessing form fields is easy as a Symfony2 form acts as an array:
-.. code-block:: html+php
-
-
-
-
-
-
-As each field is a Field instance, it cannot be displayed as show above; use
-one of the wrapper method instead.
-
-The ``widget()`` method renders the HTML representation of a field:
-
-.. code-block:: html+php
-
- widget() ?>
+.. configuration-block::
+
+ .. code-block:: jinja
+
+ {{ form.title }}
+
+ {# access a field (first_name) nested in a group (user) #}
+ {{ form.user.first_name }}
+
+ .. code-block:: html+php
+
+
+
+
+
+
+As each field is a Field instance, it cannot be displayed as shown above; use
+one of the helpers instead.
+
+The ``render`` helper renders the HTML representation of a field:
+
+.. configuration-block::
+
+ .. code-block:: jinja
+
+ {{ form.title|render }}
+
+ .. code-block:: html+php
+
+ render($form['title']) ?>
.. note::
- The field's widget is selected based on the field class name (more
- information below).
+ The field's template is selected based on the field's class name, as you will
+ learn later.
-The ``label()`` method renders the ``
+ {% form_theme form ['HelloBundle::form.twig', 'HelloBundle::form.twig', 'HelloBundle::hello_form.twig'] %}
-The field wrappers also have a ``render()`` method to render a field "row":
+A theme can be attached to a whole form (as above) or just for a field group:
.. code-block:: jinja
- form('#') ?>
- errors() ?>
-
- render() ?>
- render() ?>
-
- hidden() ?>
-
-
+ {% form_theme form.user 'HelloBundle::form.twig' %}
-The ``render()`` method uses the ``field_group.php`` and ``row.php`` templates
-for rendering:
+Finally, customizing the representation of all forms of an application is
+possible via configuration:
-.. code-block:: html+php
+.. configuration-block::
-
+ .. code-block:: yaml
- errors() ?>
+ # app/config/config.yml
+ twig.config:
+ form:
+ resources: [BlogBundle::form.twig]
-
+ // app/config/config.php
+ $container->loadFromExtension('twig', 'config', array('form' => array(
+ 'resources' => array('BlogBundle::form.twig'),
+ )));
-As for any other method, the ``render()`` method accepts a template as an
-argument to override the default representation:
-
-.. code-block:: html+php
+Prototyping
+-----------
- render('HelloBundle:Form:group/div/field_group.php') ?>
+When prototyping a form, you can use the ``render`` helper on the form instead
+of manually rendering all fields:
+
+.. configuration-block::
+
+ .. code-block:: jinja
+
+
+
+As there is no block/template defined for the ``Form`` class, the one of its
+parent class - ``FieldGroup`` - is used instead:
+
+.. configuration-block::
+
+ .. code-block:: jinja
+
+ {# TwigBundle::form.twig #}
+
+ {% block field_group %}
+ {{ field|render_errors }}
+ {% for child in field %}
+ {% if not child.ishidden %}
+
+
+ hidden($field) ?>
.. caution::
- The ``render()`` method is not very flexible and should only be used to
+ The ``render`` method is not very flexible and should only be used to
build prototypes.