Thymeleaf compares #locale expression object with string
I want to set the th: class attribute depending on the locale of the context using the #locale expression object.
I tried
th:class="${#locale}=='en'?'active':''"
th:class="${#locale=='en'}?'active':''"
Both of them result in false, but when I print it with th: text = "$ {# locale} I got the correct language code (en, es).
Any idea how to compare the #locale object with the locale code?
+2
source to share
3 answers
Based on the answer posted by David_Garcia , I can solve my problem like this:
th:class="__${#locale}__=='en'?'active':''
+9
source to share
This is the problem I told the Thymeleaf guys.
It must be resolved #locale
first before comparing it to "en". You can do this by adding 2 underscores at the beginning and end of the expression you want to resolve first. In your case, it will be something like this:
th:call="$({__#locale__}=='en'?'active':'')"
+2
source to share