Skip to content

Commit a9648e8

Browse files
committed
feature #3742 [2.5][Templating] Add documentation about generating versioned URLs (romainneutron)
This PR was merged into the master branch. Discussion ---------- [2.5][Templating] Add documentation about generating versioned URLs | Q | A | ------------- | --- | Doc fix? | no | New docs? | symfony/symfony#10593 | Applies to | 2.5+ Commits ------- f6af251 [Templating] Add documentation about generating versioned URLs
2 parents be6c79d + f6af251 commit a9648e8

File tree

3 files changed

+102
-71
lines changed

3 files changed

+102
-71
lines changed

book/templating.rst

Lines changed: 19 additions & 0 deletions
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

Lines changed: 12 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy