How to get the portlet ID in the Asset Publisher template

Issue

  • How can I obtain the portlet ID, which is used for advanced styling, within the Freemarker template of the Asset Publisher?

Environment

  • Liferay DXP 7.4+

Resolution

  • The portlet ID used for advanced styling is a combination of the portlet name and the instance ID (if applicable). It can be constructed manually in the Freemarker template using the following code:
    <#assign portletName = portletDisplay.getRootPortlet().getPortletName()>
    <#assign instanceId = portletDisplay.getInstanceId()>

    <#if instanceId != "">
      <#assign portletId = portletName + "_INSTANCE_" + instanceId>
    <#else>
      <#assign portletId = portletName>
    <#/#if>

    Portlet ID: ${portletId}
  • For portlets that cannot be instantiated, the instance ID will be empty, resulting in the portlet ID being just the portlet name.

 

 

这篇文章有帮助吗?
0 人中有 0 人觉得有帮助