Skip to content

Commit

Permalink
[TwigBundle] Add documentation about generating absolute URL with the…
Browse files Browse the repository at this point in the history
… asset function
  • Loading branch information
romainneutron committed Mar 17, 2014
1 parent 739f43f commit bd947c7
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 71 deletions.
16 changes: 16 additions & 0 deletions book/templating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,22 @@ assets won't be cached when deployed. For example, ``/images/logo.png`` might
look like ``/images/logo.png?v2``. For more information, see the :ref:`ref-framework-assets-version`
configuration option.

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

If you need absolute URLs for assets, you can set the third argument (or the
``absolute`` argument) to ``true``:

.. configuration-block::

.. code-block:: html+jinja

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

.. code-block:: html+php

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

.. index::
single: Templating; Including stylesheets and JavaScripts
single: Stylesheets; Including stylesheets
Expand Down
17 changes: 17 additions & 0 deletions components/templating/helpers/assetshelper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ You can also specify a URL to use in the second parameter of the constructor::

Now URLs are rendered like ``http://cdn.example.com/images/logo.png``.

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

You can also use the third argument of the helper to force an absolute URL:

.. code-block:: html+php

<img src="<?php echo $view['assets']->getUrl('images/logo.png', null, true) ?>">
<!-- renders as:
<img src="http://yourwebsite.com/foo/bar/images/logo.png">
-->

.. note::

If you already set a URL in the constructor, using the third argument of
``getUrl`` will not affect the generated URL.

Versioning
----------

Expand Down
Loading

0 comments on commit bd947c7

Please sign in to comment.