How to add portlet in liferay theme.
Some times liferay developer need to embed or add portlet in theme.
To do this follow the below process:
Add the below code in portal_normal.vm file..
## Set the portlet id
#set ($locPortletId = "signup_WAR_signupportlet")
#set ($portletPreferencesFactoryUtil = $portal.getClass().forName("com.liferay.portlet.PortletPreferencesFactoryUtil"))
#set ($portletSetup = $portletPreferencesFactoryUtil.getLayoutPortletSetup($layout, $locPortletId))
#if ($portletSetup.getValue("portletSetupShowBorders", "") != "false")
#set ($temp = $portletSetup.setValue("portletSetupShowBorders", "false"))
#set ($temp = $portletSetup.store())
#end
#set ($embeddedPortletURL = $portletURLFactory.create($request, $locPortletId, $layout.plid, "RENDER_PHASE"))
## Make sure it's in popup mode, otherwise it doesn't embed nicely.
#set ($VOID = $embeddedPortletURL.setWindowState("pop_up"))
#set ($VOID = $embeddedPortletURL.setPortletMode("view"))
## You can set parameters if you like
##set ($VOID = $embeddedPortletURL.setParameter("some_parameter", "some_value"))
## The iframe. You'll have to set the width of the iframe.
<iframe frameborder="0" id="${locPortletId}custom_frame" src="${embeddedPortletURL.toString()}" scrolling="no" width="100%"></iframe>
<script type="text/javascript">
AUI().use('aui-resize-iframe', function(A) {
A.one('#${locPortletId}custom_frame').plug(A.Plugin.ResizeIframe);
});
</script>
Enjoy...
To do this follow the below process:
Add the below code in portal_normal.vm file..
## Set the portlet id
#set ($locPortletId = "signup_WAR_signupportlet")
#set ($portletPreferencesFactoryUtil = $portal.getClass().forName("com.liferay.portlet.PortletPreferencesFactoryUtil"))
#set ($portletSetup = $portletPreferencesFactoryUtil.getLayoutPortletSetup($layout, $locPortletId))
#if ($portletSetup.getValue("portletSetupShowBorders", "") != "false")
#set ($temp = $portletSetup.setValue("portletSetupShowBorders", "false"))
#set ($temp = $portletSetup.store())
#end
#set ($embeddedPortletURL = $portletURLFactory.create($request, $locPortletId, $layout.plid, "RENDER_PHASE"))
## Make sure it's in popup mode, otherwise it doesn't embed nicely.
#set ($VOID = $embeddedPortletURL.setWindowState("pop_up"))
#set ($VOID = $embeddedPortletURL.setPortletMode("view"))
## You can set parameters if you like
##set ($VOID = $embeddedPortletURL.setParameter("some_parameter", "some_value"))
## The iframe. You'll have to set the width of the iframe.
<iframe frameborder="0" id="${locPortletId}custom_frame" src="${embeddedPortletURL.toString()}" scrolling="no" width="100%"></iframe>
<script type="text/javascript">
AUI().use('aui-resize-iframe', function(A) {
A.one('#${locPortletId}custom_frame').plug(A.Plugin.ResizeIframe);
});
</script>
Enjoy...
Thank you for posting this necessary article.
ReplyDeleteIf you have time please take a glance on my site hemlarm .
Is there any way to add a second "portlet zone" in a theme ?? I mean, i dont want to add a specific portlet in a theme, instead, another drop zone where users can add any portlet they need
ReplyDelete