liferayliferay-6velocityliferay-velocityliferay-theme

How to check logged user in liferay velocity?


I have a requirement that I have to display sign in url in webcontent, if user not logged in and also need to display if user logged I have to display sign out hyper link. I have searched somewhere got $is_signed_in is for checking user logged in or not. After that I have added the below code to my requirement. Even though user is logged or not it is displaying "To know more please Sign In". Why condition failed? and how to check user logged in or not in liferay velocity? I have observed that I am not getting the values of $is_signed_in,$sign_in_url,$sign_out_url

 #if(!$is_signed_in)   

      To know more please <a href="$sign_in_url">Sign In</a>

    #else

         click here to <a href="$sign_out_url">Sign Out</a>
   #end

Solution

  • $is_signed_in is available in themes, not in webcontent templates.

    Try

    #set ($themeDisplay = $httpServletRequest.getAttribute("THEME_DISPLAY"))
    $themeDisplay.isSignedIn()
    

    this should work in webcontent templates.

    (Thanks @Gonzalo for the reminder to initialize $themeDisplay prior to use)