I am currently working on a list component in AEM 6.4.8 which shows the last edited date for the pages listed. For this I'm using the built in HTL properties like so:
${'dd MMMM yyyy' @ format=item.lastModified}
Now I am trying to update this so it can be used in various languages rather than just in English. The same property above can also have a locale, and that is working fine. However, that is fairly meaningless since that would still be hardcoded to a single locale. So I've been trying to fetch the language value of the current page from the backend. So when I hardcode this value in the HTL like this:
${'dd MMMM yyyy' @ format=item.lastModified,locale='sv'}
It works just fine - component is rendered properly and month names are printed in Swedish. However, when I try to get value from the backend and the backend returns the value 'sv' I get an error, and I'm not sure if this is a bug or something that I am missing. This is the HTL:
${'dd MMMM yyyy' @ format=item.lastModified,locale=item.language}
And the error I get when trying to use this is:
org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: Invalid locale format: 'sv' at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:510) [org.apache.sling.scripting.core:2.0.54] at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:552) [org.apache.sling.engine:2.7.2] at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:44) [org.apache.sling.engine:2.7.2] at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:82) [org.apache.sling.engine:2.7.2] at com.day.cq.wcm.core.impl.WCMDeveloperModeFilter.doFilterWithErrorHandling(WCMDeveloperModeFilter.java:164) [com.day.cq.wcm.cq-wcm-core:5.11.312] at com.day.cq.wcm.core.impl.WCMDeveloperModeFilter.doFilter(WCMDeveloperModeFilter.java:135) [com.day.cq.wcm.cq-wcm-core:5.11.312]
So it is complaining about an invalid locale format - despite the value being exactly the same in the logs as what I hardcoded on the HTL frontend. So, is this a bug? Or is it simply not possible to fetch values from the backend for the HTL date? Or am I doing something else wrong?
Solved! Go to Solution.
Views
Replies
Total Likes
Send language code from backend without single quote, it will resolve the issue.
return "sv";
Hi @Richard_Bystrom,
Can you let know the data type of "language" (item.language used in your HTL) in backend. Is it a Locale object or String?
Hello! Currently I am returning it as a simple string from the backend, like this:
return "'sv'";
I also tried escaping the quotes, to no success.
Send language code from backend without single quote, it will resolve the issue.
return "sv";
Views
Likes
Replies
Views
Likes
Replies