Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Get localized expando value in freemarker template
Hi, there!
I have the following problem. I've added a new custom attribute to my site pages. The attribute is of type "Localized text". Now I need to get and show this attribute value in one of my freemarker theme templates. However, I'm not able to do it by some reason. The site is multi-lingual and I want to view the correct value of this attribute according to the locale that is set currently. Code of type:
returns a result of type extended_hash, but I cannot access its elements the way I need.
I tried this way:
as well as:
and also:
but I got only debug errors saying that the value is evaluated to null or missing.
Any help or advice will be appreciated!
Thanks in advance!
Eli
I have the following problem. I've added a new custom attribute to my site pages. The attribute is of type "Localized text". Now I need to get and show this attribute value in one of my freemarker theme templates. However, I'm not able to do it by some reason. The site is multi-lingual and I want to view the correct value of this attribute according to the locale that is set currently. Code of type:
<#assign expandoAttribute = layout.getExpandoBridge().getAttribute("ATTRIBUTE_NAME") />
returns a result of type extended_hash, but I cannot access its elements the way I need.
I tried this way:
${expandoAttribute.get( locale )}
as well as:
<#assign value = expandoAttribute[locale] />
and also:
<#list expandoAttribute?keys as key>
<#if key == locale>
<#assign value = expandoAttribute[key] />
<!--#if-->
<!--#list-->
but I got only debug errors saying that the value is evaluated to null or missing.

Any help or advice will be appreciated!
Thanks in advance!
Eli
Massimo Bevilacqua, modified 8 Years ago.
Regular Member
Posts: 210
Join Date: 12/27/16
Recent Posts
HI,
Try to print the key value to see if your the key locale is present.
Otherwise try to use values instead of key(I had problem iterating map with keys)
Try to print the key value to see if your the key locale is present.
<#list expandoAttribute?keys as key>
${key}
<!--#list-->
Otherwise try to use values instead of key(I had problem iterating map with keys)
<#list expandoAttribute?values as field>
${field}
<!--#list-->
Yes, this prints the correct keys and values but if I have 2 values for this attribute( for example en_GB and es_ES translations ), then I got all of them and I need to print only the current one - the one that is relevant to the current site locale.
Massimo Bevilacqua, modified 8 Years ago.
Regular Member
Posts: 210
Join Date: 12/27/16
Recent Posts
Which version of liferay are you using?
Liferay 7, ga4
Massimo Bevilacqua, modified 8 Years ago.
Regular Member
Posts: 210
Join Date: 12/27/16
Recent Posts
Could you please paste your template code so I can test it?
Ok, so here are the steps to reproduce the scenario:
1. Go to Control Panel -> Configuration -> Custom Fields -> Page -> Add Custom Field
2. Add a new field with key: Page Title, type: Localized Text.
3. Go to theme portal_normal.flt template and add the following code:
4. Go and test this on some page on frontend.
1. Go to Control Panel -> Configuration -> Custom Fields -> Page -> Add Custom Field
2. Add a new field with key: Page Title, type: Localized Text.
3. Go to theme portal_normal.flt template and add the following code:
<#assign expandoAttribute = layout.getExpandoBridge().getAttribute("Page Title") />
<!-- Print the attribute value with the current locale -->
<p>${expandoAttribute[locale]}</p>
or
<p>${expandoAttribute.get( locale )}</p>
4. Go and test this on some page on frontend.
Massimo Bevilacqua, modified 8 Years ago.
Regular Member
Posts: 210
Join Date: 12/27/16
Recent Posts
Now I understand the problem,
if you have custom attribute and for example you add as value "Hello" in english and "Hallo" in german when you retrive the values liferay print
"HelloHallo"
This is how data is stored in my case:
I made some test but I was not able to solve the problem, I am sorry.
if you have custom attribute and for example you add as value "Hello" in english and "Hallo" in german when you retrive the values liferay print
"HelloHallo"
This is how data is stored in my case:
{valueId=49020, companyId=20116, tableId=48997, columnId=49000, rowId=49019, classNameId=29201, classPK=49018, data=HalloHello}
I made some test but I was not able to solve the problem, I am sorry.
Ok, Massimo!
Thank you very much anyway!
Thank you very much anyway!
I finally managed to find a solution that works for me and it looks like this:
Apparently, it was a matter of choosing the correct freemarker method to access the extended_hash value. Might not be the best solution, but at least it helped me get what I need
<#list expandoAttribute?keys as key>
<#if key == locale>
<#assign value = expandoAttribute?values[key_index] />
<!--#if-->
<!--#list-->
${value}
Apparently, it was a matter of choosing the correct freemarker method to access the extended_hash value. Might not be the best solution, but at least it helped me get what I need

I also had this issue and it took me several hours to finally resolve it (Liferay Community Edition Portal 7.0.6 GA7)... It's really unfortunate that in this version of LR we still have this issue, preventing people from doing basic actions, like properly iterate a collection...
Anyway, your example helped a lot, with a remark that
key_index
should actually be
key?index
Hi All,
Is there any better solution provided in the recent versions?
Thanks in Advance.
Regards,
Aravinth
Is there any better solution provided in the recent versions?
Thanks in Advance.
Regards,
Aravinth
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™