I'm realizing a theme with liferay using velocity. I would like to add some functions to the theme homepage only in the case the user logs in the portal for the first time. How can I use velocity (portal_normal.vm) to achieve that?
2 Answers
As stated by @Olaf Kock it is not suggested to use the business logic in the theme section.
But, If you want to do it anyway then Liferay provides a set of Velocity Variables that can be accessed in the Themes. Which includes the User
details too.
These are some of the User
related Variables available globally in themes,
$user_id,$is_default_user,$user_first_name,$user_middle_name .... $user_login_ip, $user_last_login_ip
You can check out more at : themes\_unstyled\templates\init.vm
inside ROOT.WAR.
So, For your specific purpose here you can use $user_last_login_ip
. If the value is null then it would be the first time the user has logged into the portal.So, use this inside the portal_normal.vm
,
#if (!$user_last_login_ip)
... do stuff here if the variable is null
#end
And, Alternately you can fetch the User last login date using and check null
to ensure whether it is his first login,
#if (!$user.getLastLoginDate())
... do stuff here if the variable is null
#end

- 5,144
- 5
- 34
- 52
Don't add this to the theme. Rather have a separate custom LoginAction for this. This will be executed on every login (you can choose pre- or post-login, I'm assuming that post-login will be appropriate) and should find some more information than I linked on this topic all over the net.
A theme is made for look&feel and should not contain any business logic - especially not when it's for a one-off purpose.

- 46,930
- 8
- 59
- 90