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 Web Content Structure image values inside an ADT
I am making an Application Display Template that shows different types of Web Content Articles (different Structures). All of the Structures have a field called "PosterImage" (image type).
I am able to get a reference to the image with code like this in the ADT:
The value of posterImage looks like key/value pairs:
But it seems to be a string (posterImage?is_string?c outputs true, posterImage?is_hash?c outputs false). How can I get these as discrete values, to assign them to Freemarker variables? In this case, I am only interested in the fileEntryId value.
I am able to get a reference to the image with code like this in the ADT:
<#assign
className = assetRenderer.getClassName()
article = assetRenderer.getArticle()
document = saxReaderUtil.read(article.getContent())
rootElement = document.getRootElement()
/>
<#list rootElement.elements() as dynamicElement>
<#if "PosterImage" == dynamicElement.attributeValue("name")>
<#assign posterImage = dynamicElement.element("dynamic-content").getData() />
<!--#if-->
<!--#list-->
The value of posterImage looks like key/value pairs:
{"groupId":"20126","name":"handshake_0.jpg","alt":"","resourcePrimeKey":"","title":"handshake_0.jpg","type":"journal","uuid":"f02ca676-f6ed-471a-a56c-e9d083b010ac","fileEntryId":"142301","resourcePrimKey":"142311"}But it seems to be a string (posterImage?is_string?c outputs true, posterImage?is_hash?c outputs false). How can I get these as discrete values, to assign them to Freemarker variables? In this case, I am only interested in the fileEntryId value.
I guess, the easiest way is to use eval. Try this:
<#assign
data = posterImage?eval
fileEntryId = data.fileEntryId
/>
<#assign
data = posterImage?eval
fileEntryId = data.fileEntryId
/>