Skip to content

Commit d0af365

Browse files
javiereguiluzwouterj
authored andcommitted
Updated Twig template to take into account asset() function changes
1 parent 40d8d00 commit d0af365

File tree

3 files changed

+29
-43
lines changed

3 files changed

+29
-43
lines changed

book/templating.rst

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,46 +1027,12 @@ assets won't be cached when deployed. For example, ``/images/logo.png`` might
10271027
look like ``/images/logo.png?v2``. For more information, see the :ref:`ref-framework-assets-version`
10281028
configuration option.
10291029

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

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

1065-
<img src="<?php echo $view['assets']->getUrl(
1066-
'images/logo.png',
1067-
null,
1068-
true
1069-
) ?>" alt="Symfony!" />
1035+
<img src="{{ absolute_url(asset('images/logo.png')) }}" alt="Symfony!" />
10701036

10711037
.. index::
10721038
single: Templating; Including stylesheets and JavaScripts
@@ -1224,7 +1190,7 @@ automatically:
12241190

12251191
.. versionadded:: 2.6
12261192
The global ``app.security`` variable (or the ``$app->getSecurity()``
1227-
method in PHP templates) is deprecated as of Symfony 2.6. Use ``app.user``
1193+
method in PHP templates) is deprecated as of Symfony 2.6. Use ``app.user``
12281194
(``$app->getUser()``) and ``is_granted()`` (``$view['security']->isGranted()``)
12291195
instead.
12301196

reference/configuration/framework.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -923,10 +923,6 @@ Now, the same asset will be rendered as ``/images/logo.png?v2`` If you use
923923
this feature, you **must** manually increment the ``assets_version`` value
924924
before each deployment so that the query parameters change.
925925

926-
It's also possible to set the version value on an asset-by-asset basis (instead
927-
of using the global version - e.g. ``v2`` - set here). See
928-
:ref:`Versioning by Asset <book-templating-version-by-asset>` for details.
929-
930926
You can also control how the query string works via the `assets_version_format`_
931927
option.
932928

@@ -1063,6 +1059,7 @@ Assume you have custom global form themes in
10631059
See :ref:`book-forms-theming-global` for more information.
10641060

10651061
.. _reference-templating-base-urls:
1062+
.. _ref-framework-assets-base-urls:
10661063

10671064
assets_base_urls
10681065
................

reference/twig_reference.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,29 @@ assets_version
126126
Returns the current version of the package, more information in
127127
:ref:`book-templating-assets`.
128128

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

0 commit comments

Comments
 (0)