Skip to content

Commit

Permalink
feature #3683 [TwigBundle] Add documentation about generating absolut…
Browse files Browse the repository at this point in the history
…e URL with the asset function (romainneutron)

This PR was merged into the master branch.

Discussion
----------

[TwigBundle] Add documentation about generating absolute URL with the asset function

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | yes (symfony/symfony#10451)
| Applies to    | 2.5+

Commits
-------

bd947c7 [TwigBundle] Add documentation about generating absolute URL with the asset function
  • Loading branch information
weaverryan committed Mar 18, 2014
2 parents fc1576a + bd947c7 commit 842fd30
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 842fd30

Please sign in to comment.