Skip to content

Commit 4a238cb

Browse files
author
pvanliefland
committed
[#814] [Form] Added html+php syntax
1 parent 29d1970 commit 4a238cb

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

cookbook/form/create_form_type_extension.rst

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -270,21 +270,31 @@ In your extension class, you have added a new variable (``image_url``), but
270270
you still need to take advantage of this new variable in your templates.
271271
You need to override the ``file_widget`` block:
272272

273-
.. code-block:: html+jinja
273+
.. configuration-block::
274+
275+
.. code-block:: html+jinja
276+
277+
{# src/Acme/DemoBundle/Resources/views/Form/fields.html.twig #}
278+
{% extends 'form_div_layout.html.twig' %}
279+
280+
{% block file_widget %}
281+
{% spaceless %}
274282

275-
{# src/Acme/DemoBundle/Resources/views/Form/fields.html.twig #}
276-
{% extends 'form_div_layout.html.twig' %}
283+
{{ block('field_widget') }}
284+
{% if image_url is not null %}
285+
<img src="{{ asset(image_url) }}"/>
286+
{% endif %}
277287

278-
{% block file_widget %}
279-
{% spaceless %}
288+
{% endspaceless %}
289+
{% endblock %}
280290

281-
{{ block('field_widget') }}
282-
{% if image_url is not null %}
283-
<img src="{{ asset(image_url) }}"/>
284-
{% endif %}
291+
.. code-block:: html+php
285292

286-
{% endspaceless %}
287-
{% endblock %}
293+
<!-- src/Acme/DemoBundle/Resources/views/Form/file_widget.html.php -->
294+
<?php echo $view['form']->widget($form) ?>
295+
<?php if (null !== $image_url): ?>
296+
<img src="<?php echo $view['assets']->getUrl($image_url) ?>"/>
297+
<?php endif ?>
288298

289299
.. note::
290300

0 commit comments

Comments
 (0)