Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Erik Nielsen
Generating Liferay URL in Velocity template for Web Content Display
June 25, 2012 11:01 AM
Answer

Erik Nielsen

Rank: New Member

Posts: 3

Join Date: June 25, 2012

Recent Posts

I would like to be able to use portletURLFactory to create a URL in a velocity template for the Web Content Display portlet. Unfortunately, according to [url=http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/CMS+Template+(Velocity)]these links, we don't have access to a real HttpServletRequest object here (and it's odd that we have access to portletURLFactory in this case).

Is there any way to get around this without using friendly URLs for any portlets to which you want to link? What I'd like to do (and what doesn't work) is something like:
1
2#set($plid = $getterUtil.getLong($portalUtil.getPlidFromPortletId($getterUtil.getLong($groupId), "portletName")))
3#set($url = $portletURLFactory.create($request, "portletName", $plid, "RENDER_PHASE"))
4## set some other parameters on the url
5## include the link


However, $url will not be populated because the call to create will not work, as far as I understand, because $request is not the real HttpServeletRequest.

Thanks,
Erik
Jelmer Kuperus
RE: Generating Liferay URL in Velocity template for Web Content Display
June 25, 2012 11:15 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1190

Join Date: March 10, 2010

Recent Posts

You could use javascript : http://www.liferay.com/web/eduardo.lundgren/blog/-/blogs/liferay-portleturl-in-javascript
Erik Nielsen
RE: Generating Liferay URL in Velocity template for Web Content Display
June 25, 2012 12:21 PM
Answer

Erik Nielsen

Rank: New Member

Posts: 3

Join Date: June 25, 2012

Recent Posts

Jelmer,

Is there a way to ensure that the portlet_url.js file gets included on a page? I know I can configure portlets to include specific JS files, but this isn't included in the page I'm building on which I'm putting the Web Content Display. Otherwise, that looks like a great solution.

Thanks,
Erik
Jelmer Kuperus
RE: Generating Liferay URL in Velocity template for Web Content Display
June 26, 2012 1:41 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1190

Join Date: March 10, 2010

Recent Posts

You include the module something like this :

1AUI().ready('liferay-portlet-url', function(A) {
2
3... code goes here
4});
Sachin Mane
RE: Generating Liferay URL in Velocity template for Web Content Display
June 26, 2012 4:52 AM
Answer

Sachin Mane

Rank: Junior Member

Posts: 76

Join Date: April 9, 2012

Recent Posts

i believe you will have access to PortletRequest (RenderRequesT) in the template.
You can use PortalUtil.getHttpServletRequest (PortletRequest portletRequest) to get the http request and then use PortletUrlFactory.
Erik Nielsen
RE: Generating Liferay URL in Velocity template for Web Content Display
June 26, 2012 7:24 AM
Answer

Erik Nielsen

Rank: New Member

Posts: 3

Join Date: June 25, 2012

Recent Posts

Thanks, that's exactly what I needed.

Erik
Michel Wicky
RE: Generating Liferay URL in Velocity template for Web Content Display
January 14, 2013 12:49 PM
Answer

Michel Wicky

Rank: Regular Member

Posts: 129

Join Date: July 2, 2010

Recent Posts

Hello Erik,

Did you got it ?

I cannot achiveve the class initialization, i don't why, may be you will find the reason or let us know about your code so i can compare.

Here is an abstract from the velocity web content template :

#foreach ($userOrganization in $userOrganizations)
#if ($userOrganization.getParentOrganization().getGroupId() == 10698)
#set ($httpRequest = $portalUtil.getHttpServletRequest())
#set ($myPlaceURL = $portletFactoryUtil.create($httpRequest, "49", $userOrganization.getGroup().getDefaultPublicPlid(), "ACTION_PHASE"))
#set ($myPlaceURL2 = $portletFactoryUtil.create($request, "49", $userOrganization.getGroup().getDefaultPublicPlid(), "ACTION_PHASE"))
$userOrganization.getGroup().getDefaultPublicPlid()
$myPlaceURL.toString()
$myPlaceURL2.toString()
## $myPlaceURL.setWindowState("normal")
## $myPlaceURL.setPortletMode("view")
## $myPlaceURL.setParameter("struts_action", "/my_places/view")
## $myPlaceURL.setParameter("groupId", $userOrganization.getGroupId().toString())
## $myPlaceURL.setParameter("privateLayout", "false")

## $myPlaceURL.toString()

<li><a href="${myPlaceURL.toString()}">$userOrganization.Name</a></li>

#set ($matched = $matched + 1)
#end
#end

Thank you
Tejas Kanani
RE: Generating Liferay URL in Velocity template for Web Content Display
May 2, 2013 5:19 AM
Answer

Tejas Kanani

Rank: Liferay Master

Posts: 653

Join Date: January 6, 2009

Recent Posts

Hi Michel,
Did you find any solution for this ? I am also not able to get HttpRequest in WCM template.

Thanks,
Tejas
Mazhar Alam
RE: Generating Liferay URL in Velocity template for Web Content Display
November 25, 2013 10:58 PM
Answer

Mazhar Alam

Rank: Regular Member

Posts: 188

Join Date: November 25, 2011

Recent Posts

I am also trying to create a sign in url into the webcontent. Still am trying to achieve this by templates and methods posted here.

If anyone have tried this, then do let me know.
Thanks