How can I get the Display Page's Asset Entry in a Liferay Freemarker

709 Views Asked by At

How can I get the Asset Entry in a Freemarker (a Fragment, Widget Template, Web Content Template, etc) inside a Display Page.

1

There are 1 best solutions below

0
Marcos Blandim On BEST ANSWER

You can use INFO_ITEM_DETAILS object from Request global variable, to get the Asset className and classPK, and then recover your Display Page Asset with AssetEntryLocalService

<#assign assetEntryLocalService = serviceLocator.findService("com.liferay.asset.kernel.service.AssetEntryLocalService")/>

<#if Request.INFO_ITEM_DETAILS??>
  <#assign 
    info_item_reference = Request.INFO_ITEM_DETAILS.getInfoItemReference()
    
    className = info_item_reference.getClassName()
    classPK = info_item_reference.getClassPK()
    
    asset = assetEntryLocalService.getEntry(className, classPK)
  />
  ${asset}
</#if>

make sure to use Freemarker's alternative (square bracket) syntax when creating a Fragment