I have some navigation in one of my thymeleaf templates.
<li class="active"><a th:href="@{/}">Home</a></li>
<li class=""><a th:href="@{/about}">About</a></li>
<li class=""><a th:href="@{/contact}">Contact</a></li>
What I want to do is set the active class of the current navigation item that we are on. Coming from the grails world we can do this easily because there are 2 very important variables available to us in a GSP.
${controllerName}
${actionName}
Now I know that I can manually setting these variables in my Spring MVC controller and passing them to the view but this does not seem like a good solution.
@Controller
@RequestMapping("/about")
public class AboutController {
@RequestMapping("/")
public String home(Model model) {
model.addAttribute("controllerName", "about");
model.addAttribute("actionName", "home");
return "about/home";
}
}
Any other way to do this?