symfony - Getting current route twig -


i want current route on twig , used 2 code fail

code 1:

 {% if app.request.get('_route') == 'my_route' %}       //do  {% endif %} 

code 2:

{% if app.request.attributes.get == 'my_route' %}       //do  {% endif %} 

use "app_dev.php" @ end of url debug , check route being used @ bottom. example show "route1" here: debug showing route1

then in twig template can use this:

{% if app.request.attributes.get('_route') == 'route1' %}     <h1>test</h1> {% endif %} 

i verified works. i'm using symfony3 though.

maybe try instead of "app.request.attributes.get()", try these:

  • app.request.pathinfo
  • app.request.uri

see if work.

also if route indeed null, try:

{% if app.request.attributes.get('_route') == '' %}     <h1>test</h1> {% endif %} 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -