Skip to content

Commit ab0d4db

Browse files
committed
Updated Twig template to take into account asset() function changes
1 parent 8b0c026 commit ab0d4db

File tree

3 files changed

+31
-49
lines changed

3 files changed

+31
-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``
@@ -1021,46 +1021,12 @@ assets won't be cached when deployed. For example, ``/images/logo.png`` might
10211021
look like ``/images/logo.png?v2``. For more information, see the :ref:`ref-framework-assets-version`
10221022
configuration option.
10231023

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

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

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

10651031
.. index::
10661032
single: Templating; Including stylesheets and JavaScripts
@@ -1218,7 +1184,7 @@ automatically:
12181184

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

reference/configuration/framework.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ templating
685685
~~~~~~~~~~
686686

687687
.. _reference-templating-base-urls:
688+
.. _ref-framework-assets-base-urls:
688689

689690
assets_base_urls
690691
................
@@ -971,10 +972,6 @@ Now, the same asset will be rendered as ``/images/logo.png?v2`` If you use
971972
this feature, you **must** manually increment the ``assets_version`` value
972973
before each deployment so that the query parameters change.
973974

974-
It's also possible to set the version value on an asset-by-asset basis (instead
975-
of using the global version - e.g. ``v2`` - set here). See
976-
:ref:`Versioning by Asset <book-templating-version-by-asset>` for details.
977-
978975
You can also control how the query string works via the `assets_version_format`_
979976
option.
980977

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
113109
set 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)