0

I try to add a class to a navlink based on the given URI. My code is like this:

<a data-th-href="#{@{menu.news.href}}" class="nav-link" th:classappend="#{#{httpServletRequest.requestURI} == #{menu.news.href}} ? 'active' : ''">

I also tried

.... th:classappend="#{httpServletRequest.requestURI == menu.news.href} ? 'nav-link active' : ''" ....

however this evaluation always returns false and no class is added. "httpServletRequest.requestURI" and "menu.news.href" are both the same ("/web/news") and there are no whitespaces in the messages.properties.

Is there something wrong about the operator or what am I missing?

1 Answers1

0

Finally found the error, hope it helps someone else:

<a class="nav-link" th:classappend="#{menu.news.href} == ${#request.requestURI} ? 'active' : ''" data-th-href="#{@{menu.news.href}}">