Skip to content

Commit f6af251

Browse files
committed
[Templating] Add documentation about generating versioned URLs
1 parent a4ef0e1 commit f6af251

File tree

3 files changed

+102
-71
lines changed

3 files changed

+102
-71
lines changed

book/templating.rst

+19
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,25 @@ If you need absolute URLs for assets, you can set the third argument (or the
10071007

10081008
<img src="<?php echo $view['assets']->getUrl('images/logo.png', null, true) ?>" alt="Symfony!" />
10091009

1010+
.. versionadded:: 2.5
1011+
Versioned URLs for assets were introduced in Symfony 2.5.
1012+
1013+
If you need versioned URLs for assets, you can set the fourth argument (or the
1014+
``version`` argument) to the desired version:
1015+
1016+
.. configuration-block::
1017+
1018+
.. code-block:: html+jinja
1019+
1020+
<img src="{{ asset('images/logo.png', version=3.0) }}" alt="Symfony!" />
1021+
1022+
.. code-block:: html+php
1023+
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.
1028+
10101029
.. index::
10111030
single: Templating; Including stylesheets and JavaScripts
10121031
single: Stylesheets; Including stylesheets

components/templating/helpers/assetshelper.rst

+12
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ is used in :phpfunction:`sprintf`. The first argument is the path and the
8080
second is the version. For instance, ``%s?v=%s`` will be rendered as
8181
``/images/logo.png?v=328rad75``.
8282

83+
.. versionadded:: 2.5
84+
On-demand versioned URLs for assets were introduced in Symfony 2.5.
85+
86+
You can also generate a versioned URL using the fourth argument of the helper:
87+
88+
.. code-block:: html+php
89+
90+
<img src="<?php echo $view['assets']->getUrl('images/logo.png', null, false, '3.0') ?>">
91+
<!-- renders as:
92+
<img src="/images/logo.png?v=3.0">
93+
-->
94+
8395
Multiple Packages
8496
-----------------
8597

0 commit comments

Comments
 (0)