Skip to content

Commit e3cc3de

Browse files
committed
Change to short php echo tags
1 parent 7acd15f commit e3cc3de

File tree

12 files changed

+37
-37
lines changed

12 files changed

+37
-37
lines changed

Diff for: components/process.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ instead::
312312
use Symfony\Component\Process\PhpProcess;
313313

314314
$process = new PhpProcess(<<<EOF
315-
<?php echo 'Hello World'; ?>
315+
<?= 'Hello World'; ?>
316316
EOF
317317
);
318318
$process->run();

Diff for: components/templating.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ which uses the template reference to actually find and load the template::
5454
.. code-block:: html+php
5555

5656
<!-- views/hello.php -->
57-
Hello, <?php echo $firstname ?>!
57+
Hello, <?= $firstname ?>!
5858

5959
The :method:`Symfony\\Component\\Templating\\PhpEngine::render` method parses
6060
the ``views/hello.php`` file and returns the output text. The second argument
@@ -85,7 +85,7 @@ to render the template originally) inside the template to render another templat
8585

8686
<?php $names = array('Fabien', ...) ?>
8787
<?php foreach ($names as $name) : ?>
88-
<?php echo $view->render('hello.php', array('firstname' => $name)) ?>
88+
<?= $view->render('hello.php', array('firstname' => $name)) ?>
8989
<?php endforeach ?>
9090

9191
Global Variables
@@ -103,7 +103,7 @@ In a template:
103103

104104
.. code-block:: html+php
105105

106-
<p>The google tracking code is: <?php echo $ga_tracking ?></p>
106+
<p>The google tracking code is: <?= $ga_tracking ?></p>
107107

108108
.. caution::
109109

@@ -123,13 +123,13 @@ JavaScript code isn't written out to your page. This will prevent things like
123123
XSS attacks. To do this, use the
124124
:method:`Symfony\\Component\\Templating\\PhpEngine::escape` method::
125125

126-
<?php echo $view->escape($firstname) ?>
126+
<?= $view->escape($firstname) ?>
127127

128128
By default, the ``escape()`` method assumes that the variable is outputted
129129
within an HTML context. The second argument lets you change the context. For
130130
example, to output something inside JavaScript, use the ``js`` context::
131131

132-
<?php echo $view->escape($var, 'js') ?>
132+
<?= $view->escape($var, 'js') ?>
133133

134134
The component comes with an HTML and JS escaper. You can register your own
135135
escaper using the

Diff for: components/templating/slotshelper.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ set in a slot is in the ``_content`` slot.
6767
<?php $view['slots']->set('title', $page->title) ?>
6868

6969
<h1>
70-
<?php echo $page->title ?>
70+
<?= $page->title ?>
7171
</h1>
7272
<p>
73-
<?php echo $page->body ?>
73+
<?= $page->body ?>
7474
</p>
7575

7676
.. note::

Diff for: create_framework/front_controller.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ And the ``hello.php`` script can now be converted to a template::
190190
<!-- example.com/src/pages/hello.php -->
191191
<?php $name = $request->get('name', 'World') ?>
192192

193-
Hello <?php echo htmlspecialchars($name, ENT_QUOTES, 'UTF-8') ?>
193+
Hello <?= htmlspecialchars($name, ENT_QUOTES, 'UTF-8') ?>
194194

195195
We have the first version of our framework::
196196

Diff for: create_framework/routing.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ As we now extract the request query parameters, simplify the ``hello.php``
3333
template as follows::
3434

3535
<!-- example.com/src/pages/hello.php -->
36-
Hello <?php echo htmlspecialchars(isset($name) ? $name : 'World', ENT_QUOTES, 'UTF-8') ?>
36+
Hello <?= htmlspecialchars(isset($name) ? $name : 'World', ENT_QUOTES, 'UTF-8') ?>
3737

3838
Now, we are in good shape to add new features.
3939

@@ -166,7 +166,7 @@ There are a few new things in the code:
166166
* Request attributes are extracted to keep our templates simple::
167167

168168
<!-- example.com/src/pages/hello.php -->
169-
Hello <?php echo htmlspecialchars($name, ENT_QUOTES, 'UTF-8') ?>
169+
Hello <?= htmlspecialchars($name, ENT_QUOTES, 'UTF-8') ?>
170170

171171
* Route configuration has been moved to its own file::
172172

Diff for: introduction/from_flat_php_to_symfony2.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ database and the Templating component to render a template and return a
593593
<ul>
594594
<?php foreach ($posts as $post): ?>
595595
<li>
596-
<a href="<?php echo $view['router']->path(
596+
<a href="<?= $view['router']->path(
597597
'blog_show',
598598
array('id' => $post->getId())
599599
) ?>">

Diff for: reference/forms/types/options/button_label.rst.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ be directly set inside the template:
1414

1515
.. code-block:: html+php
1616

17-
<?php echo $view['form']->widget($form['save'], array('label' => 'Click me')) ?>
17+
<?= $view['form']->widget($form['save'], array('label' => 'Click me')) ?>

Diff for: reference/forms/types/options/preferred_choices.rst.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ when rendering the field:
6060

6161
.. code-block:: php
6262

63-
<?php echo $view['form']->widget($form['publishAt'], array(
63+
<?= $view['form']->widget($form['publishAt'], array(
6464
'separator' => '====='
6565
)) ?>

Diff for: templating.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ template - a text file parsed by PHP that contains a mix of text and PHP code:
3535
<title>Welcome to Symfony!</title>
3636
</head>
3737
<body>
38-
<h1><?php echo $page_title ?></h1>
38+
<h1><?= $page_title ?></h1>
3939

4040
<ul id="navigation">
4141
<?php foreach ($navigation as $item): ?>
4242
<li>
43-
<a href="<?php echo $item->getHref() ?>">
44-
<?php echo $item->getCaption() ?>
43+
<a href="<?= $item->getHref() ?>">
44+
<?= $item->getCaption() ?>
4545
</a>
4646
</li>
4747
<?php endforeach ?>

Diff for: templating/PHP.rst

+16-16
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ the ``extend()`` call:
136136
<!-- app/Resources/views/Hello/index.html.php -->
137137
<?php $view->extend('AppBundle::layout.html.php') ?>
138138

139-
Hello <?php echo $name ?>!
139+
Hello <?= $name ?>!
140140

141141
The ``AppBundle::layout.html.php`` notation sounds familiar, doesn't it? It
142142
is the same notation used to reference a template. The ``::`` part simply
@@ -200,7 +200,7 @@ decorating the template. In the ``index.html.php`` template, define a
200200

201201
<?php $view['slots']->set('title', 'Hello World Application') ?>
202202

203-
Hello <?php echo $name ?>!
203+
Hello <?= $name ?>!
204204

205205
The base layout already has the code to output the title in the header:
206206

@@ -238,7 +238,7 @@ Create a ``hello.html.php`` template:
238238
.. code-block:: html+php
239239

240240
<!-- app/Resources/views/Hello/hello.html.php -->
241-
Hello <?php echo $name ?>!
241+
Hello <?= $name ?>!
242242

243243
And change the ``index.html.php`` template to include it:
244244

@@ -247,7 +247,7 @@ And change the ``index.html.php`` template to include it:
247247
<!-- app/Resources/views/Hello/index.html.php -->
248248
<?php $view->extend('AppBundle::layout.html.php') ?>
249249

250-
<?php echo $view->render('AppBundle:Hello:hello.html.php', array('name' => $name)) ?>
250+
<?= $view->render('AppBundle:Hello:hello.html.php', array('name' => $name)) ?>
251251

252252
The ``render()`` method evaluates and returns the content of another template
253253
(this is the exact same method as the one used in the controller).
@@ -268,7 +268,7 @@ If you create a ``fancy`` action, and want to include it into the
268268
.. code-block:: html+php
269269

270270
<!-- app/Resources/views/Hello/index.html.php -->
271-
<?php echo $view['actions']->render(
271+
<?= $view['actions']->render(
272272
new \Symfony\Component\HttpKernel\Controller\ControllerReference('AppBundle:Hello:fancy', array(
273273
'name' => $name,
274274
'color' => 'green',
@@ -320,7 +320,7 @@ updated by changing the configuration:
320320

321321
.. code-block:: html+php
322322

323-
<a href="<?php echo $view['router']->path('hello', array('name' => 'Thomas')) ?>">
323+
<a href="<?= $view['router']->path('hello', array('name' => 'Thomas')) ?>">
324324
Greet Thomas!
325325
</a>
326326

@@ -344,9 +344,9 @@ Symfony provides the ``assets`` tag to deal with them easily:
344344

345345
.. code-block:: html+php
346346

347-
<link href="<?php echo $view['assets']->getUrl('css/blog.css') ?>" rel="stylesheet" type="text/css" />
347+
<link href="<?= $view['assets']->getUrl('css/blog.css') ?>" rel="stylesheet" type="text/css" />
348348

349-
<img src="<?php echo $view['assets']->getUrl('images/logo.png') ?>" />
349+
<img src="<?= $view['assets']->getUrl('images/logo.png') ?>" />
350350

351351
The ``assets`` helper's main purpose is to make your application more
352352
portable. Thanks to this helper, you can move the application root directory
@@ -374,13 +374,13 @@ Output Escaping
374374
When using PHP templates, escape variables whenever they are displayed to the
375375
user::
376376

377-
<?php echo $view->escape($var) ?>
377+
<?= $view->escape($var) ?>
378378

379379
By default, the ``escape()`` method assumes that the variable is outputted
380380
within an HTML context. The second argument lets you change the context. For
381381
instance, to output something in a JavaScript script, use the ``js`` context::
382382

383-
<?php echo $view->escape($var, 'js') ?>
383+
<?= $view->escape($var, 'js') ?>
384384

385385
Form Theming in PHP
386386
-------------------
@@ -396,7 +396,7 @@ file in order to customize the ``integer_widget`` fragment.
396396

397397
<!-- app/Resources/views/form/integer_widget.html.php -->
398398
<div class="integer_widget">
399-
<?php echo $view['form']->block(
399+
<?= $view['form']->block(
400400
$form,
401401
'form_widget_simple',
402402
array('type' => isset($type) ? $type : "number")
@@ -567,7 +567,7 @@ original template:
567567
<?php if ($required) { $label_attr['class'] = trim((isset($label_attr['class']) ? $label_attr['class'] : '').' required'); } ?>
568568
<?php if (!$compound) { $label_attr['for'] = $id; } ?>
569569
<?php if (!$label) { $label = $view['form']->humanize($name); } ?>
570-
<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>
570+
<label <?php foreach ($label_attr as $k => $v) { printf('%s="%s" ', $view->escape($k), $view->escape($v)); } ?>><?= $view->escape($view['translator']->trans($label, array(), $translation_domain)) ?></label>
571571

572572
<!-- customization -->
573573
<?php if ($required) : ?>
@@ -588,14 +588,14 @@ original template:
588588

589589
<!-- Original content -->
590590
<input
591-
type="<?php echo isset($type) ? $view->escape($type) : 'text' ?>"
592-
<?php if (!empty($value)): ?>value="<?php echo $view->escape($value) ?>"<?php endif ?>
593-
<?php echo $view['form']->block($form, 'widget_attributes') ?>
591+
type="<?= isset($type) ? $view->escape($type) : 'text' ?>"
592+
<?php if (!empty($value)): ?>value="<?= $view->escape($value) ?>"<?php endif ?>
593+
<?= $view['form']->block($form, 'widget_attributes') ?>
594594
/>
595595

596596
<!-- Customization -->
597597
<?php if (isset($help)) : ?>
598-
<span class="help"><?php echo $view->escape($help) ?></span>
598+
<span class="help"><?= $view->escape($help) ?></span>
599599
<?php endif ?>
600600

601601
.. _`@Template`: https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/view

Diff for: templating/escaping.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ use output escaping, use the special ``escape()`` view method:
7676

7777
.. code-block:: html+php
7878

79-
Hello <?php echo $view->escape($name) ?>
79+
Hello <?= $view->escape($name) ?>
8080

8181
By default, the ``escape()`` method assumes that the variable is being rendered
8282
within an HTML context (and thus the variable is escaped to be safe for HTML).
@@ -85,7 +85,7 @@ in a JavaScript string, use the ``js`` context:
8585

8686
.. code-block:: html+php
8787

88-
var myMsg = 'Hello <?php echo $view->escape($name, 'js') ?>';
88+
var myMsg = 'Hello <?= $view->escape($name, 'js') ?>';
8989

9090
.. _`Cross Site Scripting`: https://en.wikipedia.org/wiki/Cross-site_scripting
9191
.. _`Output Escaping`: https://twig.symfony.com/doc/2.x/api.html#escaper-extension

Diff for: translation.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ The translator service is accessible in PHP templates through the
318318

319319
.. code-block:: html+php
320320

321-
<?php echo $view['translator']->trans('Symfony is great') ?>
321+
<?= $view['translator']->trans('Symfony is great') ?>
322322

323-
<?php echo $view['translator']->transChoice(
323+
<?= $view['translator']->transChoice(
324324
'{0} There are no apples|{1} There is one apple|]1,Inf[ There are %count% apples',
325325
10,
326326
array('%count%' => 10)

0 commit comments

Comments
 (0)