File tree Expand file tree Collapse file tree 2 files changed +18
-9
lines changed Expand file tree Collapse file tree 2 files changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -784,18 +784,23 @@ The following example shows how to detect if the user agent prefers "safe" conte
784
784
785
785
return $response;
786
786
787
- UrlHelper
788
- -------
787
+ Generating Relative and Absolute URLs
788
+ -------------------------------------
789
789
790
- Generating absolute (and relative) URLs for a given path is a common need
791
- in lots of applications. In Twig templates this is trivial thanks to the
792
- absolute_url() and relative_path() functions. The same functionality can
793
- be found in the :class: `Symfony\\ Component\\ HttpFoundation\\ UrlHelper ` class,
794
- which can be injected as a service anywhere in your application. This class
795
- provides two public methods called getAbsoluteUrl() and getRelativePath()::
790
+ .. versionadded :: 5.4
796
791
797
- // src/Normalizer/UserApiNormalizer.php
792
+ The feature to generate relative and absolute URLs was introduced in Symfony 5.4.
793
+
794
+ Generating absolute and relative URLs for a given path is a common need
795
+ in some applications. In Twig templates you can use the
796
+ :ref: `absolute_url() <reference-twig-function-absolute-url >` and
797
+ :ref: `relative_path() <reference-twig-function-relative-path >` functions to do that.
798
798
799
+ The :class: `Symfony\\ Component\\ HttpFoundation\\ UrlHelper ` class provides the
800
+ same functionality for PHP code via the ``getAbsoluteUrl() `` and ``getRelativePath() ``
801
+ methods. You can inject this as a service anywhere in your application::
802
+
803
+ // src/Normalizer/UserApiNormalizer.php
799
804
namespace App\Normalizer;
800
805
801
806
use Symfony\Component\HttpFoundation\UrlHelper;
Original file line number Diff line number Diff line change @@ -225,6 +225,8 @@ Returns the absolute URL (with scheme and host) for the given route. If
225
225
Read more about :doc: `Symfony routing </routing >` and about
226
226
:ref: `creating links in Twig templates <templates-link-to-pages >`.
227
227
228
+ .. _reference-twig-function-absolute-url :
229
+
228
230
absolute_url
229
231
~~~~~~~~~~~~
230
232
@@ -239,6 +241,8 @@ Returns the absolute URL (with scheme and host) from the passed relative path. C
239
241
:ref: `asset() function <reference-twig-function-asset >` to generate absolute URLs
240
242
for web assets. Read more about :ref: `Linking to CSS, JavaScript and Image Assets <templates-link-to-assets >`.
241
243
244
+ .. _reference-twig-function-relative-path :
245
+
242
246
relative_path
243
247
~~~~~~~~~~~~~
244
248
You can’t perform that action at this time.
0 commit comments