java - Play Framework: How do I change active class on route change -
i using play framework 2 java , bootstrap helper in project , want apply active
class on sidebar link click. using side nav bar navigation , default 1 link has active
class on page load, thats why in every time 1 link highlighted active link, how change class="active"
on route or link change, there way check route path our html scala template file.
here side bar navigation code.
<ul class="nav nav-list"> <li class="active"><a href="/menu1">menu1</a></li> <li><a href="/menu2">menu2</a></li> <li><a href="/menu3">menu3</a></li> </ul>
here routes
file
get /menu1 com.demo.project.controllers.democontroller.menu1() /menu2 com.demo.project.controllers.democontroller.menu2() /menu3 com.demo.project.controllers.democontroller.menu3()
please give me suggestion on it!
finally got solution problem, sharing solution others too. firstly created method inside html scala template file.
@activelink(currentpath:string) = @{ if(request.path.equals(currentpath)) "active" }
now need call 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 final solution, if 1 has solution or approaching different way same please share also.
Comments
Post a Comment