Liferay Asset Publisher ADT get Image URL

Viewed 164

I have created a structure in Liferay 7.2 that has an image selector. When I add the following to the ADT to get the image

<#assign
    artImg = saxReaderUtil.createXPath("dynamic-element[@name='Imagean48']")
/>

it doesn't return the URL but instead returns a list.

<img src=" {" classpk":1923313,"groupid":"1912582","name":"spc_desktop_welcome_image3_benefits.jpg","alt":"man="" in="" suit","title":"spc_desktop_welcome_image3_benefits.jpg","type":"document","uuid":"db10a245-881c-d09c-ab64-4aeebc1581f0","fileentryid":"1923313","resourceprimkey":"2474428"}="" "="">

Is it possible to get just the URL of the image?

1 Answers

Evaluate artImg to a hash

<#assign
  artImg = saxReaderUtil.createXPath("dynamic-element[@name='Imagean48']")
  artImgHash = artImg?eval
/>

Get artImg DLFileEntry and then its URL

<#assign
  dlFileEntryLocalService = serviceLocator.findService("com.liferay.document.library.kernel.service.DLFileEntryLocalService")
  dlURLHelper = serviceLocator.findService("com.liferay.document.library.util.DLURLHelper")

  artImgDLFile = dlFileEntryLocalService.getFileEntryByUuidAndGroupId(artImgHash.uuid, artImgHash.grouId)
  artImgURL = dlURLHelper.getImagePreviewURL(artImgDLFile, themeDisplay)
/>

Then you can just use it in your img

<img src="${artImgURL}"/>

Note: I've replicated your artImg = saxReaderUtil.createXPath... line but I don't think it works. The right way would be something like this:

<#assign 
  journal = entry.getAssetRenderer().getArticle()
  rootElement = saxReaderUtil.read(journal.content).getRootElement()
  artImg = rootElement.selectSingleNode("dynamic-element[@name='Imagean48']")
/>
Related