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:
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
Post a Comment