19

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

walidtlili
  • 840
  • 2
  • 13
  • 36

2 Answers2

68

This is because you put the path function try like this

{% set current_path = app.request.get('_route') %}
{{ current_path }}
Constantin
  • 1,258
  • 10
  • 9
-1

In the twig template, there is a global variable activeRoute.

For example {{ dump(activeRoute) }} will give you the route name.

There is one example at vendor/shopware/storefront/Resources/views/storefront/component/address/address-personal.html.twig:40

GitHub Link

With this source code.

{% if activeRoute == 'frontend.account.login.page' %}
   {% set isLoginPage = true %}
{% endif %}