Thursday, May 29, 2014

How to display logged in user full name ?

Here is the Velocity template:
#set ($userLS = $portal.getClass().forName('com.liferay.portal.service.UserLocalServiceUtil'))
#set ($userId = $getterUtil.getLong($request.get("theme-display").get("user-id")))
#set ($user = $userLS.getUserById($userId))

<div class="user-welcome">
    <span class="username">$user.getFullName() </span>
</div>
If you want to display username with welcome message:
#set ($userLS = $portal.getClass().forName('com.liferay.portal.service.UserLocalServiceUtil'))
#set ($userId = $getterUtil.getLong($request.get("theme-display").get("user-id")))
#set ($user = $userLS.getUserById($userId))

<div class="user-welcome">
    #if($user.isMale())
        <span class="welcome-msg">Bienvenido</span><br>
    #else
        <span class="welcome-msg">Bienvenida</span><br>
    #end
    <span class="username">$user.getFullName() $user.getLastName()</span>
</div>

No comments:

Post a Comment