Skip to content

Commit e24376c

Browse files
committed
[symfony#2735] Minor tweaks to the big, nice refactoring of the templating component done by WouterJ
1 parent 15b2141 commit e24376c

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

components/templating/helpers/assetshelper.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,30 @@ Assets Helper
55
=============
66

77
The assets helper's main purpose is to make your application more portable by
8-
generating assets' paths:
8+
generating asset paths:
99

1010
.. code-block:: html+php
1111

1212
<link href="<?php echo $view['assets']->getUrl('css/style.css') ?>" rel="stylesheet">
1313

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

16+
The assets helper can then be configured to render paths to a CDN or modify
17+
the paths in case your assets live in a sub-directory if your host (e.g. ``http://example.com/app``).
18+
1619
Configure Paths
1720
---------------
1821

1922
By default, the assets helper will prefix all paths with a slash. You can
20-
extend this by configuring a basepath in the first argument of the
23+
configure this by passing a base assets path as the first argument of the
2124
constructor::
2225

2326
use Symfony\Component\Templating\Helper\AssetsHelper;
2427

2528
// ...
2629
$templateEngine->set(new AssetsHelper('/foo/bar'));
2730

28-
Now, if you use the helper everything will be prefixed with ``/foo/bar``:
31+
Now, if you use the helper, everything will be prefixed with ``/foo/bar``:
2932

3033
.. code-block:: html+php
3134

@@ -63,13 +66,13 @@ second is the version. For instance, ``%s?v=%s`` will be rendered as
6366
Multiple Packages
6467
-----------------
6568

66-
Paths are internally handled by packages. The component provides 2 packages by
67-
default:
69+
Asset path generation is handled internally by packages. The component provides
70+
2 packages by default:
6871

6972
* :class:`Symfony\\Component\\Templating\\Asset\\PathPackage`
7073
* :class:`Symfony\\Component\\Templating\\Asset\\UrlPackage`
7174

72-
You can also have multiple packages::
75+
You can also use multiple packages::
7376

7477
// ...
7578
$templateEngine->set(new AssetsHelper());

components/templating/helpers/slotshelper.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ Slots Helper
55
============
66

77
More often than not, templates in a project share common elements, like the
8-
well-known header and footer. The static HTML code can be placed in a layout file
9-
and the dynamic sections are replaced by slots, which are filled by the child
10-
template; the layout file decorates the child template.
8+
well-known header and footer. Using this helper, the static HTML code can
9+
be placed in a layout file along with "slots", which represent the dynamic
10+
parts that will change on a page-by-page basis. These slots are then filled
11+
in by different children template. In other words, the layout file decorates
12+
the child template.
1113

1214
Displaying Slots
13-
~~~~~~~~~~~~~~~~
15+
----------------
1416

1517
The slots are accessible by using the slots helper (``$view['slots']``). Use
1618
:method:`Symfony\\Component\\Templating\\Helper\\SlotsHelper::output` to
@@ -47,7 +49,7 @@ the content of the subtemplate.
4749
$templateEngine->set(new SlotsHelper());
4850

4951
Extending Templates
50-
~~~~~~~~~~~~~~~~~~~
52+
-------------------
5153

5254
The :method:`Symfony\\Component\\Templating\\PhpEngine::extend` method is called in the
5355
sub-template to set its parent template. Then
@@ -72,7 +74,7 @@ is in the ``_content`` slot.
7274

7375
.. note::
7476

75-
Multiple levels of inheritance is possible: a layout can extend an other
77+
Multiple levels of inheritance is possible: a layout can extend another
7678
layout.
7779

7880
For large slots, there is also an extended syntax:

components/templating/introduction.rst

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ Usage
2626

2727
The :class:`Symfony\\Component\\Templating\\PhpEngine` class is the entry point
2828
of the component. It needs a
29-
:class:`template name parser <Symfony\\Component\\Templating\\TemplateNameParserInterface>`
29+
template name parser (:class:`Symfony\\Component\\Templating\\TemplateNameParserInterface`)
3030
to convert a template name to a
31-
:class:`template reference <Symfony\\Component\\Templating\\TemplateReferenceInterface>`
32-
and :class:`template loader <Symfony\\Component\\Templating\\Loader\\LoaderInterface>`
33-
to find the template associated to a reference::
31+
template reference (:class:`Symfony\\Component\\Templating\\TemplateReferenceInterface`).
32+
It also needs a template loader (:class:`Symfony\\Component\\Templating\\Loader\\LoaderInterface`)
33+
which uses the template reference to actually find and load the template::
3434

3535
use Symfony\Component\Templating\PhpEngine;
3636
use Symfony\Component\Templating\TemplateNameParser;
@@ -57,16 +57,16 @@ The ``$view`` variable
5757

5858
In all templates parsed by the ``PhpEngine``, you get access to a mysterious
5959
variable called ``$view``. That variable holds the current ``PhpEngine``
60-
instance. That means you get access to a bunch of methods that makes your life
60+
instance. That means you get access to a bunch of methods that make your life
6161
easier.
6262

6363
Including Templates
6464
-------------------
6565

66-
The best way to share a snippet of template code is to define a template that
67-
can then be included into other templates. As the ``$view`` variable is an
66+
The best way to share a snippet of template code is to create a template that
67+
can then be included by other templates. As the ``$view`` variable is an
6868
instance of ``PhpEngine``, you can use the ``render`` method (which was used
69-
to render the template) inside the template to render another template::
69+
to render the template originally) inside the template to render another template::
7070

7171
<?php $names = array('Fabien', ...) ?>
7272
<?php foreach ($names as $name) : ?>
@@ -76,18 +76,20 @@ to render the template) inside the template to render another template::
7676
Output Escaping
7777
---------------
7878

79-
When you display variables to the user, you should escape them using the
79+
When you render variables, you should probably escape them so that HTML or
80+
JavaScript code isn't written out to your page. This will prevent things like
81+
XSS attacks. To do this, use the
8082
:method:`Symfony\\Component\\Templating\\PhpEngine::escape` method::
8183

8284
<?php echo $view->escape($firstname) ?>
8385

8486
By default, the ``escape()`` method assumes that the variable is outputted
8587
within an HTML context. The second argument lets you change the context. For
86-
instance, to output something in a JavaScript script, use the ``js`` context::
88+
example, to output something inside JavaScript, use the ``js`` context::
8789

8890
<?php echo $view->escape($var, 'js') ?>
8991

90-
The components comes with a HTML and JS escaper. You can register your own
92+
The component comes with an HTML and JS escaper. You can register your own
9193
escaper using the
9294
:method:`Symfony\\Component\\Templating\\PhpEngine::setEscaper` method::
9395

@@ -101,10 +103,10 @@ Helpers
101103
-------
102104

103105
The Templating component can be easily extended via helpers. The component has
104-
2 build-in helpers:
106+
2 built-in helpers:
105107

106-
* :doc:`/components/helpers/assetshelper`
107-
* :doc:`/components/helpers/slotshelper`
108+
* :doc:`/components/templating/helpers/assetshelper`
109+
* :doc:`/components/templating/helpers/slotshelper`
108110

109111
Before you can use these helpers, you need to register them using
110112
:method:`Symfony\\Component\\Templating\\PhpEngine::set`::

0 commit comments

Comments
 (0)