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 value of select field in Application Display Template
Hi Everyone,I am working with Liferay -7.0. I have a Select Field in my structure, where I can select multiple options. I am trying to get the values of the field in Application Display Template (ADT). I am able to get the values of other text fields using saxReader but not able to get the value of select field. This is the sample code I have written in ADT
<#if entries?has_content>
<#list entries as curEntry>
<#assign renderer = curEntry.getAssetRenderer()>
<#assign className = renderer.getClassName()>
<#assign article = renderer.getArticle() >
<#if className == "com.liferay.journal.model.JournalArticle">
<#assign document = saxReaderUtil.read(article.getContent()) >
<#assign rootElement = document.getRootElement() >
<#list rootElement.elements() as dynamicElement >
<#if "body" == dynamicElement.attributeValue("name") >
<#assign title= dynamicElement.element("dynamic-content").getText() >
<strong>${title} </strong>
</#if>
</#if>
</#list>
</#if>
Can anyone please help me out with the code to get value of select field in Application Display Template.Thanks in advance.
<#if entries?has_content>
<#list entries as curEntry>
<#assign renderer = curEntry.getAssetRenderer()>
<#assign className = renderer.getClassName()>
<#assign article = renderer.getArticle() >
<#if className == "com.liferay.journal.model.JournalArticle">
<#assign document = saxReaderUtil.read(article.getContent()) >
<#assign rootElement = document.getRootElement() >
<#list rootElement.elements() as dynamicElement >
<#if "body" == dynamicElement.attributeValue("name") >
<#assign title= dynamicElement.element("dynamic-content").getText() >
<strong>${title} </strong>
</#if>
</#if>
</#list>
</#if>
Can anyone please help me out with the code to get value of select field in Application Display Template.Thanks in advance.
Hi ,
For fetching field value from select you can use below code snippet, you can also use below code for fetching other value s
For fetching field value from select you can use below code snippet, you can also use below code for fetching other value s
<#if entries?has_content>
<#list entries as curEntry>
<#assign renderer = curEntry.getAssetRenderer()>
<#assign className = renderer.getClassName()>
<#if className == "com.liferay.journal.model.JournalArticle">
<#assign fields = renderer.getDDMFormValuesReader().getDDMFormValues().getDDMFormFieldValues() />
<#list fields as field>
<#if field.getName() == "selectName">
<#assign selectValue = jsonFactoryUtil.createJSONArray(field.getValue().getString(locale)).getString(0) />
${selectValue}
<!--#if-->
<#if field.getName() == "textName">
<#assign textValue = field.getValue().getString(locale) />
${textValue}
<!--#if-->
<!--#list-->
<!--#if-->
<!--#list-->
<!--#if-->
Hi,
As Mohammed writes, you can access from ADT the attributes of the structure but it is not the right way.
It will be nice to include your web content model in your ADT.
The web content model can natively read the web content structure.
Of course, sometimes ADT must access to an attribute of a content to make a filter or an order but the asset publisher can do this and do it better.
Like making a Liferay Ext, you should always thinking if it is the right way to do this.
See the complete explanation in this blog :
https://liferay.dev/blogs/-/blogs/divide-and-conquer-rendering-structured-web-content-with-the-asset-publisher
As Mohammed writes, you can access from ADT the attributes of the structure but it is not the right way.
It will be nice to include your web content model in your ADT.
The web content model can natively read the web content structure.
Of course, sometimes ADT must access to an attribute of a content to make a filter or an order but the asset publisher can do this and do it better.
Like making a Liferay Ext, you should always thinking if it is the right way to do this.
See the complete explanation in this blog :
https://liferay.dev/blogs/-/blogs/divide-and-conquer-rendering-structured-web-content-with-the-asset-publisher
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™