Skip to content

Commit 7451e33

Browse files
javiereguiluzGuikingone
authored andcommitted
Removed more PHP template examples
1 parent eaadf72 commit 7451e33

File tree

5 files changed

+38
-116
lines changed

5 files changed

+38
-116
lines changed

reference/configuration/framework.rst

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,15 +1018,9 @@ You can group assets into packages, to specify different base URLs for them:
10181018
10191019
Now you can use the ``avatars`` package in your templates:
10201020

1021-
.. configuration-block:: php
1021+
.. code-block:: html+twig
10221022

1023-
.. code-block:: html+twig
1024-
1025-
<img src="{{ asset('...', 'avatars') }}">
1026-
1027-
.. code-block:: html+php
1028-
1029-
<img src="<?php echo $view['assets']->getUrl('...', 'avatars') ?>">
1023+
<img src="{{ asset('...', 'avatars') }}">
10301024

10311025
Each package can configure the following options:
10321026

@@ -1052,15 +1046,9 @@ equivalent) as well as assets rendered with Assetic.
10521046

10531047
For example, suppose you have the following:
10541048

1055-
.. configuration-block::
1056-
1057-
.. code-block:: html+twig
1058-
1059-
<img src="{{ asset('images/logo.png') }}" alt="Symfony!" />
1060-
1061-
.. code-block:: php
1049+
.. code-block:: html+twig
10621050

1063-
<img src="<?php echo $view['assets']->getUrl('images/logo.png') ?>" alt="Symfony!" />
1051+
<img src="{{ asset('images/logo.png') }}" alt="Symfony!" />
10641052

10651053
By default, this will render a path to your image such as ``/images/logo.png``.
10661054
Now, activate the ``version`` option:

reference/forms/twig_reference.rst

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -319,21 +319,12 @@ reference the variables on the ``name`` field, accessing the variables is
319319
done by using a public ``vars`` property on the
320320
:class:`Symfony\\Component\\Form\\FormView` object:
321321

322-
.. configuration-block::
322+
.. code-block:: html+twig
323323

324-
.. code-block:: html+twig
325-
326-
<label for="{{ form.name.vars.id }}"
327-
class="{{ form.name.vars.required ? 'required' : '' }}">
328-
{{ form.name.vars.label }}
329-
</label>
330-
331-
.. code-block:: html+php
332-
333-
<label for="<?php echo $view['form']->get('name')->vars['id'] ?>"
334-
class="<?php echo $view['form']->get('name')->vars['required'] ? 'required' : '' ?>">
335-
<?php echo $view['form']->get('name')->vars['label'] ?>
336-
</label>
324+
<label for="{{ form.name.vars.id }}"
325+
class="{{ form.name.vars.required ? 'required' : '' }}">
326+
{{ form.name.vars.label }}
327+
</label>
337328

338329
+------------------------+-------------------------------------------------------------------------------------+
339330
| Variable | Usage |

reference/forms/types/collection.rst

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -69,47 +69,25 @@ address as its own input text box::
6969

7070
The simplest way to render this is all at once:
7171

72-
.. configuration-block::
72+
.. code-block:: twig
7373
74-
.. code-block:: twig
75-
76-
{{ form_row(form.emails) }}
77-
78-
.. code-block:: php
79-
80-
<?php echo $view['form']->row($form['emails']) ?>
74+
{{ form_row(form.emails) }}
8175
8276
A much more flexible method would look like this:
8377

84-
.. configuration-block::
85-
86-
.. code-block:: html+twig
87-
88-
{{ form_label(form.emails) }}
89-
{{ form_errors(form.emails) }}
90-
91-
<ul>
92-
{% for emailField in form.emails %}
93-
<li>
94-
{{ form_errors(emailField) }}
95-
{{ form_widget(emailField) }}
96-
</li>
97-
{% endfor %}
98-
</ul>
99-
100-
.. code-block:: html+php
78+
.. code-block:: html+twig
10179

102-
<?php echo $view['form']->label($form['emails']) ?>
103-
<?php echo $view['form']->errors($form['emails']) ?>
80+
{{ form_label(form.emails) }}
81+
{{ form_errors(form.emails) }}
10482

105-
<ul>
106-
<?php foreach ($form['emails'] as $emailField): ?>
107-
<li>
108-
<?php echo $view['form']->errors($emailField) ?>
109-
<?php echo $view['form']->widget($emailField) ?>
110-
</li>
111-
<?php endforeach ?>
112-
</ul>
83+
<ul>
84+
{% for emailField in form.emails %}
85+
<li>
86+
{{ form_errors(emailField) }}
87+
{{ form_widget(emailField) }}
88+
</li>
89+
{% endfor %}
90+
</ul>
11391

11492
In both cases, no input fields would render unless your ``emails`` data
11593
array already contained some emails.
@@ -368,15 +346,9 @@ be added to your underlying array due to the `allow_add`_ option.
368346
The prototype field can be rendered via the ``prototype`` variable in the
369347
collection field:
370348

371-
.. configuration-block::
372-
373-
.. code-block:: twig
374-
375-
{{ form_row(form.emails.vars.prototype) }}
376-
377-
.. code-block:: php
349+
.. code-block:: twig
378350
379-
<?php echo $view['form']->row($form['emails']->vars['prototype']) ?>
351+
{{ form_row(form.emails.vars.prototype) }}
380352
381353
Note that all you really need is the "widget", but depending on how you're
382354
rendering your form, having the entire "form row" may be easier for you.

reference/forms/types/repeated.rst

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,17 @@ The repeated field type is actually two underlying fields, which you can
6969
render all at once, or individually. To render all at once, use something
7070
like:
7171

72-
.. configuration-block::
72+
.. code-block:: twig
7373
74-
.. code-block:: twig
75-
76-
{{ form_row(form.password) }}
77-
78-
.. code-block:: php
79-
80-
<?php echo $view['form']->row($form['password']) ?>
74+
{{ form_row(form.password) }}
8175
8276
To render each field individually, use something like this:
8377

84-
.. configuration-block::
85-
86-
.. code-block:: twig
87-
88-
{# .first and .second may vary in your use - see the note below #}
89-
{{ form_row(form.password.first) }}
90-
{{ form_row(form.password.second) }}
91-
92-
.. code-block:: php
78+
.. code-block:: twig
9379
94-
<?php echo $view['form']->row($form['password']['first']) ?>
95-
<?php echo $view['form']->row($form['password']['second']) ?>
80+
{# .first and .second may vary in your use - see the note below #}
81+
{{ form_row(form.password.first) }}
82+
{{ form_row(form.password.second) }}
9683
9784
.. note::
9885

security.rst

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -913,19 +913,11 @@ Access Control in Templates
913913
If you want to check if the current user has a role inside a template, use
914914
the built-in ``is_granted()`` helper function:
915915

916-
.. configuration-block::
917-
918-
.. code-block:: html+twig
919-
920-
{% if is_granted('ROLE_ADMIN') %}
921-
<a href="...">Delete</a>
922-
{% endif %}
923-
924-
.. code-block:: html+php
916+
.. code-block:: html+twig
925917

926-
<?php if ($view['security']->isGranted('ROLE_ADMIN')): ?>
927-
<a href="...">Delete</a>
928-
<?php endif ?>
918+
{% if is_granted('ROLE_ADMIN') %}
919+
<a href="...">Delete</a>
920+
{% endif %}
929921

930922
Securing other Services
931923
.......................
@@ -1096,19 +1088,11 @@ Retrieving the User in a Template
10961088
In a Twig Template this object can be accessed via the :ref:`app.user <reference-twig-global-app>`
10971089
key:
10981090

1099-
.. configuration-block::
1100-
1101-
.. code-block:: html+twig
1102-
1103-
{% if is_granted('IS_AUTHENTICATED_FULLY') %}
1104-
<p>Username: {{ app.user.username }}</p>
1105-
{% endif %}
1091+
.. code-block:: html+twig
11061092

1107-
.. code-block:: html+php
1108-
1109-
<?php if ($view['security']->isGranted('IS_AUTHENTICATED_FULLY')): ?>
1110-
<p>Username: <?php echo $app->getUser()->getUsername() ?></p>
1111-
<?php endif; ?>
1093+
{% if is_granted('IS_AUTHENTICATED_FULLY') %}
1094+
<p>Username: {{ app.user.username }}</p>
1095+
{% endif %}
11121096

11131097
.. _security-logging-out:
11141098

0 commit comments

Comments
 (0)