Play Framework: How do I change active class on route change

后端 未结 1 718
谎友^
谎友^ 2021-01-05 17:12

I am using Play Framework 2 for Java and Bootstrap Helper in my project and I want to apply active class on sidebar link click. I am using side nav bar for navi

相关标签:
1条回答
  • 2021-01-05 17:37

    Finally I got solution for my problem, I am sharing my solution for others too. Firstly I created a method inside my html scala template file.

    @activeLink(currentPath:String) = @{
    if(request.path.equals(currentPath)) "active"
    }
    

    Now need to call the above method inside class attribute of anchor tag.

    <ul class="nav nav-list">
     <li class="@activeLink("/menu1")"><a href="/menu1">Menu1</a></li>
     <li class="@activeLink("/menu2")"><a href="/menu2">Menu2</a></li>
     <li class="@activeLink("/menu3")"><a href="/menu3">Menu3</a></li>
    </ul>
    

    Here is my final solution, If some one has another solution or approaching different way for the same so please share those also.

    0 讨论(0)
提交回复
热议问题