
Add runtime portlets to a layout
Intro #
In some cases you may need to have a portlet show up on every single page every time. Instead of adding it manually everytime you create a new page, you can embed portlets in your custom Layout Template
Since Liferay version 4.3.x we have the ability to create runtime portlets and store them in layout files.
Layout example #
Here is an example:
<table id="layout-grid"> <tr> <td class="lfr-column thirty" id="left" valign="top"> $processor.processPortlet("71") $processor.processColumn("left") </td> <td class="lfr-column seventy" id="column-1" valign="top"> $processor.processPortlet("73") $processor.processColumn("column-1") </td> </tr> </table>
This is a typical layout template, with runtime portlets (navigation and breadcrumb) forced to always be above every other portlet.
Managing Instanceable Portlets #
In case you want to embed instanceable portlets, you can do it this way:
$processor.processPortlet("71_INSTANCE_abc1")
where abc1 can be a random four character code to differentiate instances of the same portlet being placed in the same page.
Embeding Custom Portlets #
If we need to add custom portlets to a page, we can do it this way:
$processor.processPortlet("portletId_WAR_webapplicationcontext_INSTANCE_abc2")
Configuring embedded portlets #
Unfortunately the $processor.processPortlet(...) mechanism does not allow configuration (portlet preferences) to be passed to the portlets. However, there's a workaround: You can use the same mechanics as in a theme - taken from LPS-15746:
$velocityPortletPreferences.setValue("portlet-setup-show-borders", "false") $velocityPortletPreferences.setValue("header-type", "none") $velocityPortletPreferences.setValue("root-layout-type", "absolute") $velocityPortletPreferences.setValue("root-layout-level", "2") $velocityPortletPreferences.setValue("included-layouts", "buderusleft") $velocityPortletPreferences.setValue("nested-children", "true") $theme.runtime("71_INSTANCE_abcd", "", $velocityPortletPreferences.toString()) $velocityPortletPreferences.reset()