?matches("home", "i")
should work, so what error message do you get with it? Another solution is nav_item.name?lower_case == "home"
. (BTW, you don't have to write .getName()
, just write .name
.)
How to compare character ignoring case in Freemarker?
-
12-07-2023 - |
Question
I need to compare strings case-insensitive in Freemarker template on Liferay Portal. I tried with:
<#if nav_item.getName().equalsIgnoreCase("home")>
<!-- if do -->
</#if>
But I get error:
Expected hash. nav_item.getName() evaluated instead to freemarker.template.SimpleScalar on line 39, column 46 in navigation.ftl.
As indicated here, I can use the common flag Case insensitive to not differentiate the lower and upper-case variation of the same letter. So I tried with:
<#if nav_item.getName()?matches("home", "i")>
But does not work! I get error.
Any help is appreciated! Thank you!
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow