RE: Get Web Content Structure image values inside an ADT

Aaron Falls, modified 6 Years ago. New Member Posts: 12 Join Date: 4/19/18 Recent Posts
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:

<#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.
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
I guess, the easiest way is to use eval. Try this:
<#assign
   data = posterImage?eval
   fileEntryId = data.fileEntryId
/>