Skip to content

Commit

Permalink
[Templating] Add documentation about generating versioned URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
romainneutron committed Apr 3, 2014
1 parent a4ef0e1 commit f6af251
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 71 deletions.
19 changes: 19 additions & 0 deletions book/templating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,25 @@ If you need absolute URLs for assets, you can set the third argument (or the

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

.. versionadded:: 2.5
Versioned URLs for assets were introduced in Symfony 2.5.

If you need versioned URLs for assets, you can set the fourth argument (or the
``version`` argument) to the desired version:

.. configuration-block::

.. code-block:: html+jinja

<img src="{{ asset('images/logo.png', version=3.0) }}" alt="Symfony!" />

.. code-block:: html+php

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

If you dont give a version or pass ``null``, the default package version will
be used. If you pass ``false``, versioned URL will be deactivated.

.. index::
single: Templating; Including stylesheets and JavaScripts
single: Stylesheets; Including stylesheets
Expand Down
12 changes: 12 additions & 0 deletions components/templating/helpers/assetshelper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ is used in :phpfunction:`sprintf`. The first argument is the path and the
second is the version. For instance, ``%s?v=%s`` will be rendered as
``/images/logo.png?v=328rad75``.

.. versionadded:: 2.5
On-demand versioned URLs for assets were introduced in Symfony 2.5.

You can also generate a versioned URL using the fourth argument of the helper:

.. code-block:: html+php

<img src="<?php echo $view['assets']->getUrl('images/logo.png', null, false, '3.0') ?>">
<!-- renders as:
<img src="/images/logo.png?v=3.0">
-->

Multiple Packages
-----------------

Expand Down
Loading

0 comments on commit f6af251

Please sign in to comment.