How can I get the current locale used in a freemarker template? I have seen implementation of <spring.message code />
I need this to do a conditional
<#if locale = DE >
.....
<#else>
....
</#if>
Comments: Comments are similar to HTML comments, but they are delimited by <#-- and --> . Comments will be ignored by FreeMarker, and will not be written to the output.
FreeMarker is a template engine, written in Java, and maintained by the Apache Foundation.
eval. This built-in evaluates a string as an FTL expression. For example "1+2"? eval returns the number 3. (To render a template that's stored in a string, use the interpret built-in instead.)
FreeMarker template error appears in logs when attempting to add a Web Content Article to a page or search for it in the Search portlet. The issue only occurs when the Summary field is empty and when using the following line in the template.
As stated by the Freemarker documentation:
Special variables are variables defined by the FreeMarker engine itself. To access them, you use the .variable_name syntax
.locale: Returns the current value of the locale setting. This is a string, for example en_US. For more information about locale strings see the setting directive.
So to access the current local within a Freemarker template you would use
The current locale is: ${.locale}
To use it in a conditional statement as per your requirements, you would do:
<#if .locale == "DE">
...
<#else>
...
</#if>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With