Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Saikat Saha
Using liferay variables in web content
November 22, 2012 10:24 PM
Answer

Saikat Saha

Rank: New Member

Posts: 22

Join Date: November 16, 2011

Recent Posts

Hi,

I need to know whether I can use the liferay variables in webcontent or not? For example can I use $user_name to display the user name throgh webcontent? If possible, then how to do it ?

Regards,
Tejas Kanani
RE: Using liferay variables in web content
November 22, 2012 11:18 PM
Answer

Tejas Kanani

Rank: Liferay Master

Posts: 653

Join Date: January 6, 2009

Recent Posts

Check this wiki. It has complete list of variables accessible in template.
Access Objects from Velocity
Tejas Kanani
RE: Using liferay variables in web content
November 22, 2012 11:35 PM
Answer

Tejas Kanani

Rank: Liferay Master

Posts: 653

Join Date: January 6, 2009

Recent Posts

Below code will give you user-id of user. Similarly you can get user name by getting currently logged in user from themeDisplay object.
$getterUtil.getLong($request.theme-display.user-id)

You can print request object by adding below line in your web content template. Which will give you all the accessible values from request object.
$request


Hope this helps.

Thanks,
Tejas
Saikat Saha
RE: Using liferay variables in web content
November 23, 2012 12:09 AM
Answer

Saikat Saha

Rank: New Member

Posts: 22

Join Date: November 16, 2011

Recent Posts

Can you please guide me to use the template for web content to do so? It will be very much helpfull if you please attach some screen shots for the same.

Thanks
Christoph Rabel
RE: Using liferay variables in web content
November 23, 2012 12:38 AM
Answer

Christoph Rabel

Rank: Regular Member

Posts: 148

Join Date: September 24, 2009

Recent Posts

Please look here, it lists the variables that are available in webcontent templates:
https://www.liferay.com/community/wiki/-/wiki/Main/Access+Objects+from+Velocity#section-Access+Objects+from+Velocity-CMS+Templates

hth
Tejas Kanani
RE: Using liferay variables in web content
November 23, 2012 12:47 AM
Answer

Tejas Kanani

Rank: Liferay Master

Posts: 653

Join Date: January 6, 2009

Recent Posts

Can you please guide me to use the template for web content to do so?

What is your exact requirement ? What do you want to display in web content display ?
Saikat Saha
RE: Using liferay variables in web content
November 28, 2012 9:50 PM
Answer

Saikat Saha

Rank: New Member

Posts: 22

Join Date: November 16, 2011

Recent Posts

I want to display the name of the user, who logs in to liferay. What do I need to do?
Juhi Kumari
RE: Using liferay variables in web content
November 28, 2012 10:19 PM
Answer

Juhi Kumari

Rank: Expert

Posts: 347

Join Date: December 12, 2011

Recent Posts

Hi Saikat,

Copy these lines in web content template to get loged in user name.
1#set($us = $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
2#set($userId = $getterUtil.getLong($request.get("theme-display").get("user-id")))
3$htmlUtil.escape($us.getUserById($userId).getFullName())


Regards
Juhi
decipher raone
RE: Using liferay variables in web content
March 11, 2014 2:45 AM
Answer

decipher raone

Rank: New Member

Posts: 1

Join Date: February 12, 2014

Recent Posts

Thanks to Liferay 6.2 for making things easier. If you want to get user's first name or last name or full name through webcontent's template just use this code
$permissionChecker.getUser().getLastName()
$permissionChecker.getUser().getFirstName()
$permissionChecker.getUser().getFullName()