سؤال

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
هل كانت مفيدة؟

المحلول

$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)

نصائح أخرى

in your theme _diff/templates/portal_normal.vm, you have add this code.

if ($is_signed_in)

            <!-- user dropdown starts -->
            <div class="btn-group pull-right" >
                <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                    <i class="icon-user"></i><span class="hidden-phone"> $user_name </span>
                    <span class="caret"></span>
                </a>
                <ul class="dropdown-menu">
                        <li><a href="$sign_out_url">Logout</a></li>
                </ul>
            </div>
            <!-- user dropdown ends -->
        #end    

Check the below link -

https://www.liferay.com/community/forums/-/message_boards/message/25175535

Try adding this code in portal-ext.properties

journal.template.velocity.restricted.variables=
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top