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.