Skip to content

Commit 00f60a8

Browse files
committed
minor #3837 More asset version details (weaverryan)
This PR was merged into the master branch. Discussion ---------- More asset version details | Q | A | ------------- | --- | Doc fix? | no | New docs? | no, but follows after #3742 | Applies to | 2.5+ Hi guys! This adds some further tweaks to the new feature and docs from #3742: * moved the absolute asset URL generation part below the new asset versioning feature in the `book/templating` page so that we talk about the "global asset versioning" (i.e. the config option in config.yml) and this new feature right next to each other. * Added some additional details to make it clear that there is a "global" asset version, and then the ability to override on an asset by asset basis. I think it's all small details, but @romainneutron if you have a quick chance to look this over, that would be awesome too. Thanks! Commits ------- 4eafdbd [#3837] Fixes thanks to stof and WouterJ 560e010 Adding more details to be clear that you can set asset version globally or locally on an asset
2 parents 21a4b9d + 4eafdbd commit 00f60a8

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

book/templating.rst

+16-13
Original file line numberDiff line numberDiff line change
@@ -991,40 +991,43 @@ assets won't be cached when deployed. For example, ``/images/logo.png`` might
991991
look like ``/images/logo.png?v2``. For more information, see the :ref:`ref-framework-assets-version`
992992
configuration option.
993993

994+
.. _`book-templating-version-by-asset`:
995+
994996
.. versionadded:: 2.5
995-
Absolute URLs for assets were introduced in Symfony 2.5.
997+
Setting versioned URLs on an asset-by-asset basis was introduced in Symfony 2.5.
996998

997-
If you need absolute URLs for assets, you can set the third argument (or the
998-
``absolute`` argument) to ``true``:
999+
If you need to set a version for a specific asset, you can set the fourth
1000+
argument (or the ``version`` argument) to the desired version:
9991001

10001002
.. configuration-block::
10011003

10021004
.. code-block:: html+jinja
10031005

1004-
<img src="{{ asset('images/logo.png', absolute=true) }}" alt="Symfony!" />
1006+
<img src="{{ asset('images/logo.png', version='3.0') }}" alt="Symfony!" />
10051007

10061008
.. code-block:: html+php
10071009

1008-
<img src="<?php echo $view['assets']->getUrl('images/logo.png', null, true) ?>" alt="Symfony!" />
1010+
<img src="<?php echo $view['assets']->getUrl('images/logo.png', null, false, '3.0') ?>" alt="Symfony!" />
1011+
1012+
If you dont give a version or pass ``null``, the default package version
1013+
(from :ref:`ref-framework-assets-version`) will be used. If you pass ``false``,
1014+
versioned URL will be deactivated for this asset.
10091015

10101016
.. versionadded:: 2.5
1011-
Versioned URLs for assets were introduced in Symfony 2.5.
1017+
Absolute URLs for assets were introduced in Symfony 2.5.
10121018

1013-
If you need versioned URLs for assets, you can set the fourth argument (or the
1014-
``version`` argument) to the desired version:
1019+
If you need absolute URLs for assets, you can set the third argument (or the
1020+
``absolute`` argument) to ``true``:
10151021

10161022
.. configuration-block::
10171023

10181024
.. code-block:: html+jinja
10191025

1020-
<img src="{{ asset('images/logo.png', version=3.0) }}" alt="Symfony!" />
1026+
<img src="{{ asset('images/logo.png', absolute=true) }}" alt="Symfony!" />
10211027

10221028
.. code-block:: html+php
10231029

1024-
<img src="<?php echo $view['assets']->getUrl('images/logo.png', null, false, '3.0') ?>" alt="Symfony!" />
1025-
1026-
If you dont give a version or pass ``null``, the default package version will
1027-
be used. If you pass ``false``, versioned URL will be deactivated.
1030+
<img src="<?php echo $view['assets']->getUrl('images/logo.png', null, true) ?>" alt="Symfony!" />
10281031

10291032
.. index::
10301033
single: Templating; Including stylesheets and JavaScripts

components/templating/helpers/assetshelper.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ second is the version. For instance, ``%s?v=%s`` will be rendered as
8383
.. versionadded:: 2.5
8484
On-demand versioned URLs for assets were introduced in Symfony 2.5.
8585

86-
You can also generate a versioned URL using the fourth argument of the helper:
86+
You can also generate a versioned URL on an asset-by-asset basis using the
87+
fourth argument of the helper:
8788

8889
.. code-block:: html+php
8990

reference/configuration/framework.rst

+4
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ Now, the same asset will be rendered as ``/images/logo.png?v2`` If you use
392392
this feature, you **must** manually increment the ``assets_version`` value
393393
before each deployment so that the query parameters change.
394394

395+
It's also possible to set the version value on an asset-by-asset basis (instead
396+
of using the global version - e.g. ``v2`` - set here). See
397+
:ref:`Versioning by Asset <book-templating-version-by-asset>` for details.
398+
395399
You can also control how the query string works via the `assets_version_format`_
396400
option.
397401

0 commit comments

Comments
 (0)