following simple code:
<li><a href="{{ path('_list') }}">List</a></li>
is there a simple way to add an class="active"
if the current page matches the _list
route?
using the newest PR-Release of symfony2 and twig as template engine
following simple code:
<li><a href="{{ path('_list') }}">List</a></li>
is there a simple way to add an class="active"
if the current page matches the _list
route?
using the newest PR-Release of symfony2 and twig as template engine
Twig allows for conditionals and the Request object is available throughout the application. If you are including the template, to get the route you want to use:
If you are using the render function, you want to use:
With that, you should be able to use:
or shorter:
Shortest version:
Sometimes useful:
SF2.2
i found a very good Bundle that handles all this stuff automagically:
https://github.com/KnpLabs/KnpMenuBundle
Symfony2.3, in Twig, try this to get uri:
This is how I do it (using Symfony 2.6)
'_homepage'
is the name of route inrouting.yml
of your bundle and the route looks like this