Skip to content

Commit 842fd30

Browse files
committed
feature #3683 [TwigBundle] Add documentation about generating absolute 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
2 parents fc1576a + bd947c7 commit 842fd30

File tree

3 files changed

+104
-71
lines changed

3 files changed

+104
-71
lines changed

book/templating.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,22 @@ assets won't be cached when deployed. For example, ``/images/logo.png`` might
991991
look like ``/images/logo.png?v2``. For more information, see the :ref:`ref-framework-assets-version`
992992
configuration option.
993993

994+
.. versionadded:: 2.5
995+
Absolute URLs for assets were introduced in Symfony 2.5.
996+
997+
If you need absolute URLs for assets, you can set the third argument (or the
998+
``absolute`` argument) to ``true``:
999+
1000+
.. configuration-block::
1001+
1002+
.. code-block:: html+jinja
1003+
1004+
<img src="{{ asset('images/logo.png', absolute=true) }}" alt="Symfony!" />
1005+
1006+
.. code-block:: html+php
1007+
1008+
<img src="<?php echo $view['assets']->getUrl('images/logo.png', null, true) ?>" alt="Symfony!" />
1009+
9941010
.. index::
9951011
single: Templating; Including stylesheets and JavaScripts
9961012
single: Stylesheets; Including stylesheets

components/templating/helpers/assetshelper.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ You can also specify a URL to use in the second parameter of the constructor::
4747

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

50+
.. versionadded:: 2.5
51+
Absolute URLs for assets were introduced in Symfony 2.5.
52+
53+
You can also use the third argument of the helper to force an absolute URL:
54+
55+
.. code-block:: html+php
56+
57+
<img src="<?php echo $view['assets']->getUrl('images/logo.png', null, true) ?>">
58+
<!-- renders as:
59+
<img src="http://yourwebsite.com/foo/bar/images/logo.png">
60+
-->
61+
62+
.. note::
63+
64+
If you already set a URL in the constructor, using the third argument of
65+
``getUrl`` will not affect the generated URL.
66+
5067
Versioning
5168
----------
5269

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