Search code examples
sensenet

How to hide/remove search box from sensenet homepage for Visitors (before login)


I want to remove search box for Visitor users on the homepage of my custom sensenet site. I want to display it only after a user is logged in to the site. I tried to achieve this with making changes in the skin.css


Solution

  • Place the following to the end of pagetemplate html's body

    <snpe:ClientContextPortlet runat="server" id="ClientContext" />
    

    This will add context information in json to the html of the page, and you'll be able to check if the current user is loggedin or not (in this case she's name is Visitor). Then add the following to the init.js (/Root/Skins/sensenet/scripts/init.js)

    $(function(){
      if(SN.Context.currentUser.name === "Visitor")
        $('.sn-quicksearch').hide();
      else
        $('.sn-quicksearch').show();
    })