0
votes


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

1

1 Answers

0
votes

Yes, of course there's a way: Use a different layout on that page - preferably one that doesn't embed the search portlet.

Also page specific CSS (containing display:none; for the search portlet) will somewhat work. Yes, the portlet will be rendered and sent - but what kind of performance impact are we speaking about? Does it make any measurable difference? If it does: Choose option 1 from above. If it doesn't: Don't bother.