I am creating a web content in liferay. I have added a template for my structure.In template,i have chosen velocity as my script language.I want to access logged in user's name in my vm script.But when i use $user.getFirstName() as declared in init.vm it doesn't work, not even with $user_first_name as used in portal_normal.vm.Can anyone help me?

But to get logged-in user details , you may have to call user service in template and need to set in separate variable using service locator.And then you can use all the methods to get login user details.

But to get logged-in user details , you may have to call user service in template and need to set in separate variable using service locator.And then you can use all the methods to get login user details.

Thanks for prompt reply.But I don't know how to call user service in template.I followed this linkhttp://www.liferay.com/community/wiki/-/wiki/Main/Access+Liferay+Services+in+Velocity#section-Access+Liferay+Services+in+Velocity-The+findService()+Methodbut here there is no description for calling user service .

It's most probably because you have to allow it via portal-ext.properties. This can be done by the property

1 journal.template.velocity.restricted.variables=

leaving it blank will allow service locator to get the service

Thanks!! I missed that.But the catch is, its still not working. My variable in template is still not getting set.I have set below mentioned variables.:#set ($user = $userLocalService.getUser($request.get("theme-display").get("user-id")))#set($userLocalService = $serviceLocator.findExceptionSafeService("com.liferay.portal.service.UserLocalService

For others who might be searching and wanting to access expando content, here's an example of how to do that:

1 2### 3## Don't forget to set journal.template.velocity.restricted.variables= 4## in portal-ext.properties; in other words, set it to nothing to unset the restriction. 5### 6 7## See http://www.liferay.com/community/forums/-/message_boards/message/14789299 8## this is where this comes from 910#set ($userLocalService= $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))11#set ($userId = $getterUtil.getLong($request.remote-user))12#set($user = $userLocalService.getUserById($userId)) 1314#set ($userFirstName=$user.getFirstName())15## This is a drop down select, so must be accessed this way16#set ($class_year = $user.getExpandoBridge().getAttribute("gradYear").get(0))17#set ($ugrad = $user.getExpandoBridge().getAttribute("UndergradSchool"))18#set ($userCount=$userLocalService.getUsersCount()) 1920<h2>Getting variables from user, system, and expando</h2>21<p>Year: $class_year</p>22<p>School: $ugrad</>23<p>First Name: $userFirstName</p>24<p>User count: $userCount </p>