Skip to content

Commit 8f9a5e0

Browse files
committed
[Routing] Improve current route block
1 parent 3c35bf4 commit 8f9a5e0

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

routing.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,15 +1545,19 @@ information in a controller via the ``Request`` object::
15451545
You can get this information in services too injecting the ``request_stack``
15461546
service to :doc:`get the Request object in a service </service_container/request>`.
15471547
In templates, use the :ref:`Twig global app variable <twig-app-variable>` to get
1548-
the request and its attributes:
1548+
the current route and its attributes:
15491549

15501550
.. code-block:: twig
15511551
1552-
{% set route_name = app.request.attributes.get('_route') %}
1553-
{% set route_parameters = app.request.attributes.get('_route_params') %}
1552+
{% set route_name = app.current_route %}
1553+
{% set route_parameters = app.current_route_parameters %}
15541554
1555-
{# use this to get all the available attributes (not only routing ones) #}
1556-
{% set all_attributes = app.request.attributes.all %}
1555+
.. versionadded:: 6.2
1556+
1557+
The ``app.current_route`` and ``app.current_route_parameters`` variables
1558+
were introduced in Symfony 6.2.
1559+
Before you had to access ``_route`` and ``_route_params`` request
1560+
attributes using ``app.request.attributes.get()``.
15571561

15581562
Special Routes
15591563
--------------

0 commit comments

Comments
 (0)