Skip to content

Commit bc18ff1

Browse files
javiereguiluzwouterj
authored andcommitted
Updated Twig template to take into account asset() function changes
1 parent 84a1afd commit bc18ff1

File tree

3 files changed

+27
-42
lines changed

3 files changed

+27
-42
lines changed

book/templating.rst

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,46 +1067,12 @@ assets won't be loaded from cache after being deployed. For example, ``/images/l
10671067
look like ``/images/logo.png?v2``. For more information, see the :ref:`reference-framework-assets-version`
10681068
configuration option.
10691069

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

1072-
If you need to set a version for a specific asset, you can set the ``version`` argument
1073-
if you are using Twig (or the fourth argument if you are using PHP) to the desired version:
1073+
.. code-block:: html+jinja
10741074

1075-
.. configuration-block::
1076-
1077-
.. code-block:: html+jinja
1078-
1079-
<img src="{{ asset('images/logo.png', version='3.0') }}" alt="Symfony!" />
1080-
1081-
.. code-block:: html+php
1082-
1083-
<img src="<?php echo $view['assets']->getUrl(
1084-
'images/logo.png',
1085-
null,
1086-
false,
1087-
'3.0'
1088-
) ?>" alt="Symfony!" />
1089-
1090-
If you don't give a version or pass ``null``, the default package version
1091-
(from :ref:`reference-framework-assets-version`) will be used. If you pass ``false``,
1092-
versioned URL will be deactivated for this asset.
1093-
1094-
If you need absolute URLs for assets, you can use the ``absolute_url`` function
1095-
if you are using Twig (or the third argument if you are using PHP) to ``true``:
1096-
1097-
.. configuration-block::
1098-
1099-
.. code-block:: html+jinja
1100-
1101-
<img src="{{ absolute_url(asset('images/logo.png')) }}" alt="Symfony!" />
1102-
1103-
.. code-block:: html+php
1104-
1105-
<img src="<?php echo $view['assets']->getUrl(
1106-
'images/logo.png',
1107-
null,
1108-
true
1109-
) ?>" alt="Symfony!" />
1075+
<img src="{{ absolute_url(asset('images/logo.png')) }}" alt="Symfony!" />
11101076

11111077
.. index::
11121078
single: Templating; Including stylesheets and JavaScripts

reference/configuration/framework.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,10 +1081,6 @@ Now, the same asset will be rendered as ``/images/logo.png?v2`` If you use
10811081
this feature, you **must** manually increment the ``version`` value
10821082
before each deployment so that the query parameters change.
10831083

1084-
It's also possible to set the version value on an asset-by-asset basis (instead
1085-
of using the global version - e.g. ``v2`` - set here). See
1086-
:ref:`Versioning by Asset <book-templating-version-by-asset>` for details.
1087-
10881084
You can also control how the query string works via the `version_format`_
10891085
option.
10901086

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)