Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbd947c7

Browse files
committed
[TwigBundle] Add documentation about generating absolute URL with the asset function
1 parent739f43f commitbd947c7

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)

[8]ページ先頭

©2009-2025 Movatter.jp