Message Boards
How to get Web Content structure field (Image) from ADT
sree p, modified 4 Years ago.
How to get Web Content structure field (Image) from ADT
Junior Member Posts: 91 Join Date: 10/3/19 Recent Posts
hello, I have created web content structure with Image field and name it as News_Image and want to get that in application display template (ADT) , Can you please let me how to do that in Liferay 7.2
Mohammed Yasin, modified 4 Years ago.
RE: How to get Web Content structure field (Image) from ADT
Liferay Master Posts: 591 Join Date: 8/8/14 Recent Posts
Hi ,
You may not be able to get structure field directly in Asset publisher Template , it will show the template corresponding to Web content , may be you need to write a custom web service and fetch those image url form template
You may not be able to get structure field directly in Asset publisher Template , it will show the template corresponding to Web content , may be you need to write a custom web service and fetch those image url form template
sree p, modified 4 Years ago.
RE: How to get Web Content structure field (Image) from ADT
Junior Member Posts: 91 Join Date: 10/3/19 Recent Posts
may be there is a way to read web content structure fields in ADT like below
<#if entries?has_content>
<#list entries as curEntry>
<#assign
renderer = curEntry.getAssetRenderer()
className = renderer.getClassName()
viewURL0 = assetPublisherHelper.getAssetViewURL(renderRequest, renderResponse, curEntry)
viewURL = renderer.getURLViewInContext(renderRequest, renderResponse, viewURL0) />
<#if className == "com.liferay.journal.model.JournalArticle">
<#assign
journalArticle = renderer.getArticle()
document = saxReaderUtil.read(journalArticle.getContent())
rootElement = document.getRootElement()
xPathSelector = saxReaderUtil.createXPath("dynamic-element[@name='subtitle']")
subtitle = xPathSelector.selectSingleNode(rootElement).getStringValue()
link = renderer.getURLViewInContext(renderRequest, renderResponse, '')
>
</#if>
${subtitle}
</#list>
</#if>
<#if entries?has_content>
<#list entries as curEntry>
<#assign
renderer = curEntry.getAssetRenderer()
className = renderer.getClassName()
viewURL0 = assetPublisherHelper.getAssetViewURL(renderRequest, renderResponse, curEntry)
viewURL = renderer.getURLViewInContext(renderRequest, renderResponse, viewURL0) />
<#if className == "com.liferay.journal.model.JournalArticle">
<#assign
journalArticle = renderer.getArticle()
document = saxReaderUtil.read(journalArticle.getContent())
rootElement = document.getRootElement()
xPathSelector = saxReaderUtil.createXPath("dynamic-element[@name='subtitle']")
subtitle = xPathSelector.selectSingleNode(rootElement).getStringValue()
link = renderer.getURLViewInContext(renderRequest, renderResponse, '')
>
</#if>
${subtitle}
</#list>
</#if>
Dominik Marks, modified 4 Years ago.
RE: How to get Web Content structure field (Image) from ADT
Regular Member Posts: 149 Join Date: 8/29/12 Recent Posts
You need to know that the web content data is saved in XML format. Here is an example how to iterate over the assets in an ADT, check if the displayed assets are Web Contents and to read the image and display it.
<#list entries as entry>
<#assign
assetRenderer = entry.getAssetRenderer()
/>
<#if assetRenderer.getClassName()=="com.liferay.journal.model.JournalArticle">
<#assign
docXml = saxReaderUtil.read(assetRenderer.getArticle().getContent())
image = docXml.valueOf("//dynamic-element[@name='News_Image']/dynamic-content/text()")
/>
<img src="${image}">
<!--#if-->
<!--#list-->
sree p, modified 4 Years ago.
RE: How to get Web Content structure field (Image) from ADT
Junior Member Posts: 91 Join Date: 10/3/19 Recent Posts
how and where can I see that XML format of web content ? and give please provide more ADT examples
sree p, modified 3 Years ago.
RE: How to get Web Content structure field (Image) from ADT
Junior Member Posts: 91 Join Date: 10/3/19 Recent Posts
Hello, this did not work src is showing/printing as {" classpk":"780056","groupid":"763443","name":"screen="" shot="" 2020-07-01="" at="" 10.41.21="" am.png","alt":"","title":"screen="" am.png","type":"journal","uuid":"2eb5d96d-5010-183b-64be-d494945f3e50","fileentryid":"780062","resourceprimkey":"768337"}, that is not giving image pagth.
sree p, modified 3 Years ago.
RE: How to get Web Content structure field (Image) from ADT
Junior Member Posts: 91 Join Date: 10/3/19 Recent PostsDominik Marks:
Hello, this did not work <img src is showing/printing as {" classpk":"780056","groupid":"763443","name":"screen="" shot="" 2020-07-01="" at="" 10.41.21="" am.png","alt":"","title":"screen="" am.png","type":"journal","uuid":"2eb5d96d-5010-183b-64be-d494945f3e50","fileentryid":"780062","resourceprimkey":"768337"}, that is not giving image pagth.
You need to know that the web content data is saved in XML format. Here is an example how to iterate over the assets in an ADT, check if the displayed assets are Web Contents and to read the image and display it. <#list entries as entry> <#assign assetRenderer = entry.getAssetRenderer() /> <#if assetRenderer.getClassName()=="com.liferay.journal.model.JournalArticle"> <#assign docXml = saxReaderUtil.read(assetRenderer.getArticle().getContent()) image = docXml.valueOf("//dynamic-element[@name='News_Image']/dynamic-content/text()") /> <img src="${image}"> <!--#if--> <!--#list-->
Jan van der Kaaden, modified 4 Years ago.
RE: How to get Web Content structure field (Image) from ADT
Junior Member Posts: 28 Join Date: 3/20/11 Recent Posts
Just take a look at 'view source' in webcontent (the 3 dots at the right top of the screen)