Pages

Thursday, 21 March 2013

Adding portlets on page using JavaScript

This is gonna be a very small post, but trust me these two lines are amazing.
This code add portlet on the current page.

1
2
3
Liferay.Portlet.add({
 portletId: portletId
});


You just have to use it inside a javascript function, like:
1
2
3
4
5
var addPortlet = function(portletId){
 Liferay.Portlet.add({
  portletId: portletId
 });
}

All now neede is to envoke this function on click on a button with propert portletId, like:

<input type="button" value="Add portlet" onClick="javascript:addPortlet('<portlet_id>')" />


and yes its done. Hope this will help.

No comments:

Post a Comment