How to get current URL or route in TWIG?

I am very new to Symfony2, and I need to check the current route in TWIG so that I can display a submenu in a template that looks like this:

{% render "CPAdminBundle:Messages:sidebarMenu" %}
{% render "CPAdminBundle:Readings:sidebarMenu" %}

In sidebar templates, I tried using the following, but it throws an error:

path(app.request.attributes.get('_route')) 

What is the right way to do what I'm trying to accomplish?

+5
source share
1 answer

The check you want to do does not apply to the view. Submissions should only take care of the show, and not make any logic.

, .
, kernel.controller event.

, app.request.attributes.get('_route') . , path().

{% if app.request.attributes.get('_route') == 'my_route' %}
{% endif %}
+22

All Articles