I know that specification says the other, but is there any way to remove portlet that was embedded in a layout? Say I have my layout with search portlet on each page, but I would like it to be on each page except one.
I already tried this topic: How to delete a portlet in Liferay 6.1 programmatically from code, using <a onclick="Liferay.Portlet.close('#p_p_id_3_'); return false;">Remove</a>
And it worked, but the portlet to be deleted was unnecessary rendered and sent to client.
I also tried this code:
ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(com.liferay.portal.kernel.util.WebKeys.THEME_DISPLAY);
Layout layout = themeDisplay.getLayout();
LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();
List<Portlet> portlets = layoutTypePortlet.getAllPortlets();
for (Portlet portlet : portlets) {
if(portlet.getPortletId().equalsIgnoreCase(portletToDeleteId)){
layoutTypePortlet.removePortletId(userId, portletToDeleteId);
LayoutLocalServiceUtil.updateLayout(layout);
}
}
But it can't list portlets embedded in layout; it only iterates through portlets I add manually from portal.
I add portlet in layout this way: $processor.processPortlet("3")
I work in Liferay Portal 6.2 GA4.
TIA