Forum Discussion

PerBonomi's avatar
7 years ago

Feels like a noob question, but..

Why does this fire for an anonymous user? <#if user?? && user.id?? && user.login != "">
  • TariqHussain's avatar
    7 years ago

    PerBonomi - 

     

    1. user?? - it is checking for the object is available or not. For the anonymous user, an object is available. 

    2.  user.id?? - it is checking for the user.id key available or not. Even for the anonymous user, this key is available. 

    3. user.login != "" - It is checking if user.login is not blank, however, for anonymous user user.login is being returned as anonymous.

    Solution: 

    if you want to check for an anonymous user you can use below code. 

     

    <#if user.anonymous>
    </#if>
    
    OR
    <#if !user.registered> </#if> OR <#if user.id != -1> </#if>