Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Unable to get the logged user screen name in velocity template - DXP?
Hi All,
I used below code in velocity template (Structures and Template) to
get the logged user screenName
#set( $user =
$permissionChecker.getUser())
Screen Name: $user.screenName<br>
Above code always giving test user related screenName eventhough logged with other user.
Actuall Result:
Always showing test user screen name eventhough logged with
other user.
Expected Result:
It should show the user screen name who is logged in to the
portal.
Can any help me out.
First, shame on your for continuing to use Velocity instead of Freemarker. Now that we have that out of the way :) ...
1. What if you use another mechanism to get the user? for example, if you use the staticUtil to load the PortalUtil class and get the user from the Request -- does it still give you the same result?
2. Can you share your velocity template with me. I will (reluctantly) add it to a local DXP on my side and try it, if #1 doesn't give you a better result.
(Can you also share the exact version SP/FP you are running)
Thank you for reply.
Version: liferay-dxp-digital-enterprise-7.0-sp6
Structure: just have one text field and am not used this text filed in template.
Template Code:
#set( $user = $permissionChecker.getUser())
Screen
Name: $user.screenName<br>
Chanakya P:Template Code:
#set( $user = $permissionChecker.getUser())
Screen Name: $user.screenName<br>
In the template editor, under "Details", there's a "Cachable" checkbox, checked by default. The help text reads:
Only uncheck when developing templates which use request handling, CMS query API, or other dynamic features.
Uncheck this, because you're using dynamic features. Otherwise it will always show the (cached) value from its first execution.
Thanks for your solution.
It is working now
Powered by Liferay™