user8772487
user8772487

Reputation:

Symfony4 Equivalent to display the current route

I'm looking to show the current route with symfony4. I try this:

{% set currentPath = app.request.attributes.get('_route') %}

but it does not work, the result is null

Thank you.

Upvotes: 0

Views: 1409

Answers (1)

dbrumann
dbrumann

Reputation: 17166

You can just get the current request's URI like this:

{% set currentPath = app.request.uri %}

If you want to reuse the current path and add/change some of the parameters you could do it something like this:

{% set routeName = app.request.attributes.get('_route') %}
{% set routeParams = app.request.attributes.get('_route_params')|merge({'some_url_param': 'a value'}) %}

{% set currentPath = path(routeName, routeParams) %}

Upvotes: 1

Related Questions