Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
venka reddy
Velocity Variables in Webcontent
May 28, 2013 6:21 AM
Answer

venka reddy

Rank: Regular Member

Posts: 230

Join Date: March 23, 2011

Recent Posts

Hi,

Is there any difference in accessing the velocity variables in Theme and Webcontent? If so, what variables i can access in webcontent?

I think below code will work for theme, not for webcontent.

#set ($userLocalService= $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
#set ($user = $userLocalService.getUserById($request.get("theme-display").get("user-id")))
#set ($emailAddress = $user.getEmailAddress())

$emailAddress



Any Suggestions!!!!
Gwowen Fu
RE: Velocity Variables in Webcontent
May 28, 2013 9:38 AM
Answer

Gwowen Fu

Rank: Expert

Posts: 253

Join Date: December 27, 2010

Recent Posts

Your code is good, Do you have this line in your portal-ext.properties:

journal.template.velocity.restricted.variables=

This makes all objects available.

-Gwowen
venka reddy
RE: Velocity Variables in Webcontent
May 28, 2013 10:32 AM
Answer

venka reddy

Rank: Regular Member

Posts: 230

Join Date: March 23, 2011

Recent Posts

Hi,

No , I didn't add this line . I will add this property and i will try it.

So, by adding this property we can access all the variables? It is only the solution? because we need to restart it!

Do you know why, liferay by default disabled?
Gwowen Fu
RE: Velocity Variables in Webcontent
May 28, 2013 11:36 AM
Answer

Gwowen Fu

Rank: Expert

Posts: 253

Join Date: December 27, 2010

Recent Posts

It is not really all objects will be available. For layout/page/conten tempalte, they have different set of objects and some of them are not enabled by defautl. You can look at this wiki to know the detail:
http://www.liferay.com/community/wiki/-/wiki/Main/Access+Objects+from+Velocity
venka reddy
RE: Velocity Variables in Webcontent
May 28, 2013 11:11 PM
Answer

venka reddy

Rank: Regular Member

Posts: 230

Join Date: March 23, 2011

Recent Posts

Hi,

I have enabled "journal.template.velocity.restricted.variables=" portlet-ext.properties file. Still i am unable to get it.

Here is my code,

#set ($userLocalService= $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
#set ($user = $userLocalService.getUserById($request.get("theme-display").get("user-id")))
#set ($emailAddress = $user.getEmailAddress())

But when i try to get variable values the output as follows,

$emailAddress ------------------------------------ $emailAddress
$user ------------------------------------- $user
$userLocalService ---------------------------- com.liferay.portal.service.impl.UserLocalServiceImpl@1a2a316
$request.get("theme-display").get("user-id") --------------------------- 10158


Here i can able to get userId from request.
Parikshit Sharma
RE: Velocity Variables in Webcontent
May 29, 2013 3:50 AM
Answer

Parikshit Sharma

Rank: New Member

Posts: 21

Join Date: January 16, 2013

Recent Posts

venka reddy:
Hi,

I have enabled "journal.template.velocity.restricted.variables=" portlet-ext.properties file. Still i am unable to get it.

Here is my code,

#set ($userLocalService= $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
#set ($user = $userLocalService.getUserById($request.get("theme-display").get("user-id")))
#set ($emailAddress = $user.getEmailAddress())

But when i try to get variable values the output as follows,

$emailAddress ------------------------------------ $emailAddress
$user ------------------------------------- $user
$userLocalService ---------------------------- com.liferay.portal.service.impl.UserLocalServiceImpl@1a2a316
$request.get("theme-display").get("user-id") --------------------------- 10158


Here i can able to get userId from request.


Try below code.
1
2#set ($userLocalService= $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
3#set ($user = $userLocalService.getUserById($getterUtil.getLong($request.get("theme-display").get("user-id"))))
4#set ($emailAddress = $user.emailAddress)
5$emailAddress
venka reddy
RE: Velocity Variables in Webcontent
May 29, 2013 4:37 AM
Answer

venka reddy

Rank: Regular Member

Posts: 230

Join Date: March 23, 2011

Recent Posts

Hi,

Got it ! mistake is userId should convert into long. Thanks!!!

Can we create url's(render) in webcontent?