title: Removing portlet embedded in Liferay Layouts
body: <p><br/>
  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.  <br/><br/>
  I already tried this topic: <a href="https://stackoverflow.com/questions/30456078/how-to-delete-a-portlet-in-liferay-6-1-programmatically-from-code">How to delete a portlet in Liferay 6.1 programmatically from code</a>, using <br/>
  <code>&lt;a onclick="Liferay.Portlet.close('#p_p_id_3_'); return false;"&gt;Remove&lt;/a&gt;</code> <br/>
  And it worked, but the portlet to be deleted was unnecessary rendered and sent to client. <br/><br/>
  I also tried this code: <br/></p>
  
  <pre><code>ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(com.liferay.portal.kernel.util.WebKeys.THEME_DISPLAY);
  Layout layout = themeDisplay.getLayout();
  LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();
  List&lt;Portlet&gt; portlets = layoutTypePortlet.getAllPortlets();
  for (Portlet portlet : portlets) {
      if(portlet.getPortletId().equalsIgnoreCase(portletToDeleteId)){
          layoutTypePortlet.removePortletId(userId, portletToDeleteId);
          LayoutLocalServiceUtil.updateLayout(layout);
      }
  }
  </code></pre>
  
  <p>But it can't list portlets embedded in layout; it only iterates through portlets I add manually from portal.<br/><br/>
  I add portlet in layout this way: <br/> <code>$processor.processPortlet("3")</code><br/><br/>
  I work in Liferay Portal 6.2 GA4.<br/>
  TIA</p>