16
votes

i'm developing an application with symfony3.
I want to get route name in twig. i did this :

 {% set current_path = path(app.request.get('_route')) %}
 {{ current_path }}

it displays the url of the current page. But i want to get route name not the path. example :

personnel_index:
    path:     /liste
    defaults: { _controller: "PersonnelBundle:Personnel:index" }
    methods:  GET

must return : personnel_index

so how can i get the route name

1
$request->attributes->get('_route'); works so try app.request.attributes.get('_route'); and see what happens.Cerad
thanks for relying but it diplays always the pathwalidtlili
Drop the path function. set current_route_name = app.request.attributes.get('_route')Cerad
aah yess thank youuwalidtlili

1 Answers

55
votes

This is because you put the path function try like this

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