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

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

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *