Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Syed Umair
Portal Url in VM
November 4, 2012 10:39 PM
Answer

Syed Umair

Rank: Junior Member

Posts: 36

Join Date: October 11, 2012

Recent Posts

Hi,
I have developed a structure and template. Currently, I am using localhost:8080 in my template, but when I will deploy my web it should not be localhost. Can anyone suggest me how to get portal url in VM template.
I can get it in jsp using themeDisplay.getPortalURL(), but I dont know how to do it in VM. emoticon

Any valuable suggestion will be appreciated. emoticon
Umair
Rishi Dev Gupta
RE: Portal Url in VM
November 4, 2012 10:53 PM
Answer

Rishi Dev Gupta

Rank: Expert

Posts: 255

Join Date: November 23, 2008

Recent Posts

Check this link this might help you

http://content.liferay.com/4.3/misc/theme-api-4.3.0.html
Jitendra Rajput
RE: Portal Url in VM
November 4, 2012 11:06 PM
Answer

Jitendra Rajput

Rank: Liferay Master

Posts: 858

Join Date: January 7, 2011

Recent Posts

Could you please try with below code .

#set ($portalUtil= $utiLocator.findUtil("com.liferay.portal.util.portalUtil"))
#set ($portalURL=$portalUtil.getPortalURL($themeDisplay))
$portalURL
Syed Umair
RE: Portal Url in VM
November 4, 2012 11:36 PM
Answer

Syed Umair

Rank: Junior Member

Posts: 36

Join Date: October 11, 2012

Recent Posts

Thnx, for your replies. I manage it to do it with

1#set($companyLocalService = $serviceLocator.findService("com.liferay.portal.service.CompanyLocalService"))
2#set($company = $companyLocalService.getCompany($company_id))
3#set($portalURL = $company.getVirtualHostname())
Rishi Dev Gupta
RE: Portal Url in VM
November 5, 2012 12:19 AM
Answer

Rishi Dev Gupta

Rank: Expert

Posts: 255

Join Date: November 23, 2008

Recent Posts

You do not need to define service variable to get company information. You will get the $company object by default in vm file, thus no need to make a database hit.

Also you will need to set the property accordingly in portal.properties, if you want to use service layer (as answered y you)
#
# Input a comma delimited list of variables which are restricted from the
# context in Velocity based Journal templates.
#
journal.template.velocity.restricted.variables=serviceLocator
Syed Umair
RE: Portal Url in VM
November 5, 2012 12:35 AM
Answer

Syed Umair

Rank: Junior Member

Posts: 36

Join Date: October 11, 2012

Recent Posts

Rishi Dev Gupta:
You do not need to define service variable to get company information. You will get the $company object by default in vm file, thus no need to make a database hit.


I have tried the $company object and it works same. And it will certainly improve the performance. emoticon