Skip to content

Commit 24a36ef

Browse files
committed
Updated Twig template to take into account asset() function changes
1 parent 56a80f8 commit 24a36ef

File tree

3 files changed

+32
-49
lines changed

3 files changed

+32
-49
lines changed

book/templating.rst

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Throughout this chapter, template examples will be shown in both Twig and PHP.
135135
web designers everywhere.
136136

137137
Twig can also do things that PHP can't, such as whitespace control,
138-
sandboxing, automatic HTML escaping, manual contextual output escaping,
138+
sandboxing, automatic HTML escaping, manual contextual output escaping,
139139
and the inclusion of custom functions and filters that only affect templates.
140140
Twig contains little features that make writing templates easier and more concise.
141141
Take the following example, which combines a loop with a logical ``if``
@@ -1019,46 +1019,12 @@ assets won't be cached when deployed. For example, ``/images/logo.png`` might
10191019
look like ``/images/logo.png?v2``. For more information, see the :ref:`ref-framework-assets-version`
10201020
configuration option.
10211021

1022-
.. _`book-templating-version-by-asset`:
1022+
If you need absolute URLs for assets, use the ``absolute_url()`` Twig function
1023+
as follows:
10231024

1024-
If you need to set a version for a specific asset, you can set the fourth
1025-
argument (or the ``version`` argument) to the desired version:
1026-
1027-
.. configuration-block::
1028-
1029-
.. code-block:: html+jinja
1030-
1031-
<img src="{{ asset('images/logo.png', version='3.0') }}" alt="Symfony!" />
1032-
1033-
.. code-block:: html+php
1034-
1035-
<img src="<?php echo $view['assets']->getUrl(
1036-
'images/logo.png',
1037-
null,
1038-
false,
1039-
'3.0'
1040-
) ?>" alt="Symfony!" />
1041-
1042-
If you don't give a version or pass ``null``, the default package version
1043-
(from :ref:`ref-framework-assets-version`) will be used. If you pass ``false``,
1044-
versioned URL will be deactivated for this asset.
1045-
1046-
If you need absolute URLs for assets, you can set the third argument (or the
1047-
``absolute`` argument) to ``true``:
1048-
1049-
.. configuration-block::
1050-
1051-
.. code-block:: html+jinja
1052-
1053-
<img src="{{ asset('images/logo.png', absolute=true) }}" alt="Symfony!" />
1054-
1055-
.. code-block:: html+php
1025+
.. code-block:: html+jinja
10561026

1057-
<img src="<?php echo $view['assets']->getUrl(
1058-
'images/logo.png',
1059-
null,
1060-
true
1061-
) ?>" alt="Symfony!" />
1027+
<img src="{{ absolute_url(asset('images/logo.png')) }}" alt="Symfony!" />
10621028

10631029
.. index::
10641030
single: Templating; Including stylesheets and JavaScripts
@@ -1216,7 +1182,7 @@ automatically:
12161182

12171183
.. versionadded:: 2.6
12181184
The global ``app.security`` variable (or the ``$app->getSecurity()``
1219-
method in PHP templates) is deprecated as of Symfony 2.6. Use ``app.user``
1185+
method in PHP templates) is deprecated as of Symfony 2.6. Use ``app.user``
12201186
(``$app->getUser()``) and ``is_granted()`` (``$view['security']->isGranted()``)
12211187
instead.
12221188

reference/configuration/framework.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ For more details, see :doc:`/cookbook/serializer`.
420420
templating
421421
~~~~~~~~~~
422422

423+
.. _ref-framework-assets-base-urls:
424+
423425
assets_base_urls
424426
................
425427

@@ -504,10 +506,6 @@ Now, the same asset will be rendered as ``/images/logo.png?v2`` If you use
504506
this feature, you **must** manually increment the ``assets_version`` value
505507
before each deployment so that the query parameters change.
506508

507-
It's also possible to set the version value on an asset-by-asset basis (instead
508-
of using the global version - e.g. ``v2`` - set here). See
509-
:ref:`Versioning by Asset <book-templating-version-by-asset>` for details.
510-
511509
You can also control how the query string works via the `assets_version_format`_
512510
option.
513511

reference/twig_reference.rst

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,12 @@ asset
9898

9999
.. code-block:: jinja
100100
101-
{{ asset(path, packageName, absolute = false, version = null) }}
101+
{{ asset(path, packageName) }}
102102
103103
``path``
104104
**type**: ``string``
105105
``packageName``
106106
**type**: ``string`` | ``null`` **default**: ``null``
107-
``absolute``
108-
**type**: ``boolean`` **default**: ``false``
109-
``version``
110-
**type**: ``string`` **default** ``null``
111107

112108
Returns a public path to ``path``, which takes into account the base path set
113109
for the package and the URL path. More information in
@@ -126,6 +122,29 @@ assets_version
126122
Returns the current version of the package, more information in
127123
:ref:`book-templating-assets`.
128124

125+
absolute_url
126+
~~~~~~~~~~~~
127+
128+
.. code-block:: jinja
129+
130+
{{ absolute_url(asset(path, packageName)) }}
131+
132+
``path``
133+
**type**: ``string``
134+
``packageName``
135+
**type**: ``string`` | ``null`` **default**: ``null``
136+
137+
Returns the absolute URL that corresponds to the given asset path and package.
138+
More information in :ref:`book-templating-assets`. For configuring the base URLs,
139+
:ref:`ref-framework-assets-base-urls`.
140+
141+
The absolute URLs generated with this function ignore the asset versioning.
142+
Combine it with the ``assets_version()`` function to append the version number:
143+
144+
.. code-block:: jinja
145+
146+
{{ absolute_url(asset('logo.png')) ~ '?' ~ assets_version('images') }}
147+
129148
form
130149
~~~~
131150

0 commit comments

Comments
 (0)