How to get current page in pages Symfony 5 without duplicate code?

  current-page, navigation, symfony, twig

I want get the current page and give an active class without duplicate code in symfony 5.
Here is the code example :

    <li class="{{ app.request.get('_route_')=='home' ? 'active':''}}">
       <a href="{{path('home')}}">Home</a> 
   </li>
    <li class="{{ app.request.get('_route_')=='contact' ? 'active':''}}">
        <a href="{{path('contact')}}">Contact</a> 
    </li>

</ul>

Source: Symfony Questions

LEAVE A COMMENT