diff --git a/book/templating.rst b/book/templating.rst index 23dbfab869a..fb5bcf00511 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -1067,46 +1067,12 @@ assets won't be loaded from cache after being deployed. For example, ``/images/l look like ``/images/logo.png?v2``. For more information, see the :ref:`reference-framework-assets-version` configuration option. -.. _`book-templating-version-by-asset`: +If you need absolute URLs for assets, use the ``absolute_url()`` Twig function +as follows: -If you need to set a version for a specific asset, you can set the ``version`` argument -if you are using Twig (or the fourth argument if you are using PHP) to the desired version: +.. code-block:: html+jinja -.. configuration-block:: - - .. code-block:: html+jinja - - Symfony! - - .. code-block:: html+php - - Symfony! - -If you don't give a version or pass ``null``, the default package version -(from :ref:`reference-framework-assets-version`) will be used. If you pass ``false``, -versioned URL will be deactivated for this asset. - -If you need absolute URLs for assets, you can use the ``absolute_url`` function -if you are using Twig (or the third argument if you are using PHP) to ``true``: - -.. configuration-block:: - - .. code-block:: html+jinja - - Symfony! - - .. code-block:: html+php - - Symfony! + Symfony! .. index:: single: Templating; Including stylesheets and JavaScripts diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index 85ba39f3b89..67a8bf70165 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -1081,10 +1081,6 @@ Now, the same asset will be rendered as ``/images/logo.png?v2`` If you use this feature, you **must** manually increment the ``version`` value before each deployment so that the query parameters change. -It's also possible to set the version value on an asset-by-asset basis (instead -of using the global version - e.g. ``v2`` - set here). See -:ref:`Versioning by Asset ` for details. - You can also control how the query string works via the `version_format`_ option. diff --git a/reference/twig_reference.rst b/reference/twig_reference.rst index 717d0dbf6e2..37f4c7a4475 100644 --- a/reference/twig_reference.rst +++ b/reference/twig_reference.rst @@ -126,6 +126,29 @@ assets_version Returns the current version of the package, more information in :ref:`book-templating-assets`. +absolute_url +~~~~~~~~~~~~ + +.. code-block:: jinja + + {{ absolute_url(asset(path, packageName)) }} + +``path`` + **type**: ``string`` +``packageName`` + **type**: ``string`` | ``null`` **default**: ``null`` + +Returns the absolute URL that corresponds to the given asset path and package. +More information in :ref:`book-templating-assets`. For configuring the base URLs, +:ref:`ref-framework-assets-base-urls`. + +The absolute URLs generated with this function ignore the asset versioning. +Combine it with the ``assets_version()`` function to append the version number: + +.. code-block:: jinja + + {{ absolute_url(asset('logo.png')) ~ '?' ~ assets_version('images') }} + form ~~~~