Alimozzaman

Liferay: add portlet in theme velocity files(*.vm)

Posted on: January 10, 2011

We can add any portlet into liferay theme files using the following way.

Create your portlet url using the help of portletURLFactory passig the fowwloing value according to your needs.

P_ID = Your required portlet ID.

PHASE = RENDER_PHASE/ACTION_PHASE

#set ($portlet_url = $portletURLFactory.create($request, “P_ID”, $page.getPlid(), “PHASE”))

Next, Set your window state , nomal/maximized for an example, mode and parameter in the following way.

$portlet_url.setWindowState(“maximized”)

$portlet_url.setPortletMode(“view”)
$portlet_url.setParameter(“struts_action”, “message/edit”)

Then use this url in the following way:

<a href=”$portlet_url.toString()”>my portlet link</a>

Enjoy adding portlet url in liferay theme files !

Advertisements

4 Responses to "Liferay: add portlet in theme velocity files(*.vm)"

Hi,

I tried using your code mentioned above but failing to get the result. Please clarify that in $page.getPlid(), is the variable $page get by you. I am using liferay 6.05 and I went through the velocity virables java file to check for $page but I didnt find it. This suggests me this is set by . Please explain what is $page here.

Also I wanted to know where are you getting the setParmeter which is set at $portlet_url.setParameter(“struts_action”, “message/edit”). I am not using struts and I don’t about it much. Are you setting the struts_action message/edit in portlet.xml of the portlet to linked in the theme and in portlet using the renderRequest.getParameter(‘struts_action’) and using PortletDispatcher to go the page I want see.

Many many thanks in advance. Please reply soon.

Hello there,
First of all, $page=$layout , from where u can get the portlet id.

Well, check portletURLFactory and u will get that method. This is basically giving you to set your action path. No, structs action path is set to structs configuration file. That is basically your action path, so if u dont use structs, then u can use your own action path there.

But anyway, this should work because this is test and verified.

You are welsome.
BR
Rony.

Thanks for reply.

I have created a portlet name themelinktest which dispatches to /html/view.jsp . So in this case what should be action path. Would it be like $portlet_url.setParameter(“mypath”, “html/view.jsp”) and in doView method of themelinktest portlet, I will use renderRequest.getParameter(“mypath”) ? Please clearify.

Thanks
Ravikant

Yes, right u are.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

Top Rated

Advertisements
%d bloggers like this: