Skip to content

[Cookbook][Forms] fix PHP template file name #4103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion cookbook/form/create_custom_field_type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ link for details), create a ``gender_widget`` block to handle this:

.. code-block:: html+php

<!-- src/Acme/DemoBundle/Resources/views/Form/gender_widget.html.twig -->
<!-- src/Acme/DemoBundle/Resources/views/Form/gender_widget.html.php -->
<?php if ($expanded) : ?>
<ul <?php $view['form']->block($form, 'widget_container_attributes') ?>>
<?php foreach ($form as $child) : ?>
Expand All @@ -151,6 +151,8 @@ link for details), create a ``gender_widget`` block to handle this:
Further, the main config file should point to the custom form template
so that it's used when rendering all forms.

When using Twig this is:

.. configuration-block::

.. code-block:: yaml
Expand Down Expand Up @@ -181,6 +183,51 @@ link for details), create a ``gender_widget`` block to handle this:
),
));

For the PHP templating engine, your configuration should look like this:

.. configuration-block::

.. code-block:: yaml

# app/config/config.yml
framework:
templating:
form:
resources:
- 'AcmeDemoBundle:Form'

.. code-block:: xml

<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:templating>
<framework:form>
<framework:resource>AcmeDemoBundle:Form</twig:resource>
</framework:form>
</framework:templating>
</framework:config>
</container>

.. code-block:: php

// app/config/config.php
$container->loadFromExtension('framework', array(
'templating' => array(
'form' => array(
'resources' => array(
'AcmeDemoBundle:Form',
),
),
),
));

Using the Field Type
--------------------

Expand Down