I have a twig-template (with twitter bootstrap) with the following code – it’s a navbar:
<ul class="nav">
<li class="active"><a href="#">Modul 1</a></li>
<li><a href="#about">Modul 2</a></li>
<li><a href="#contact">Modul 3</a></li>
</ul>
This code is in my global.html.twig. So I want to change the class=”active” in the list element depending on the page that is opened.
How can I achieve this without adding too much logic in my template?
The only way to achieve this without too much overhead is the use of KnpLabs/KnpMenuBundle.
In your global.html.twig:
In your Module1 bundle directory:
MenufolderMenuBuilder.phpas follows:–