Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need a versionadded directive in this file too


.. 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