How to append a class to an element with th:classappend
only if the user has a specific role?
Something like this:
<div th:classappend="${hasRole('EDITOR')?'glow':''}"></div>
I'm using Spring Boot, Spring Security and Thymeleaf.
How to append a class to an element with th:classappend
only if the user has a specific role?
Something like this:
<div th:classappend="${hasRole('EDITOR')?'glow':''}"></div>
I'm using Spring Boot, Spring Security and Thymeleaf.
I found the solution on Thymeleaf "extras" Spring Security GitHub page:
<div th:classappend="${#authorization.expression('hasRole(''EDITOR'')')?'glow':''}"></div>
You can use the request variable, which points to the current HttpServletRequest:
<div th:classappend="${#request.isUserInRole('EDITOR')?'glow':''}"></div>