We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45189
    • 35 Posts
    I have a link in the header chunk that goes to a sign in page, it says "sign in here". Once you login, the header link should change to "Hello Username Z".

    The problem i'm having is it doesn't change on all pages. Like it works at first on the sign in page, but if you start navigating the site afterwards (or after logging out), sometimes it shows Header A, sometimes it shows Header B. I can't figure out a pattern as to why some pages work and some don't. And then if I go to another browser, the header greets whoever I had last logged in until I clear the site cache and flush stuff.

    I did this login functionality for another site recently and used the Personalize snippet, and it worked fine then. So I've tried that, and variations of this, which I found in another post on the forum:

    [[!+modx.user.id:if=`[[!+modx.user.id]]`:eq:=`0`:then=`Not logged in. <a href="[[~123]]">Login</a>?`:else=`Welcome [[!+modx.user.username]]!`]]

    The only difference is that other site uses modx 2.2.8 and the new one is on 2.2.9

    I've spent hours trying to figure out what's going wrong sad

    This question has been answered by shonna. See the first response.

      • 3109 ☆ A M B ☆
      • 894 Posts
      Make sure you call your login snippet un-cached also the code you posted has an error there is a ? after the closing a tag of the Login and you have a ! after modx.user.username.

      Try using this:

      [[!+modx.user.id:if=`[[!+modx.user.id]]`:eq:=`0`:then=`Not logged in. <a href="[[~123]]">Login</a>`:else=`Welcome [[!+modx.user.username]]`]]
      


      Hopefully that works, good luck.

        Benjamin Marte
        Interactive Media Developer
        Follow Me on Twitter | Visit my site | Learn MODX
        • 45189
        • 35 Posts
        Yeah, that still didn't work sad the same thing is happening. Btw there was a ? and ! because it's supposed to read like this:
        If not logged in: "Not logged in. Login?" (and then you click this to go to the login page)
        If logged in: "Welcome Username1!"

        This is my Login code:

        [[!Login? &loginTpl=`lgnLoginTpl` &logoutTpl=`tpl-login_logout` &errTpl=`lgnErrTpl` &loginResourceId=`12` &logoutResourceId=`20`]]

          • 30912
          • 463 Posts
          I usually use Personalize for this:

          Personalize Chunk
          [[!Personalize? &yesChunk=`Logout` &noChunk=`Login_Box`]]


          Login_Box (we have a JS dropdown for the login panel, but it could just be a link)

           <div id="topnav" class="topnav"><a href="[[~76]]" class="signin"><span>Login </span></a> </div>


          Logout
          <a href="[[~76? &service=`logout`]]" title="Logout">Logout</a>


          Thats using the latest version of Personlize on a 2.2.9 install.

          As a side note, i've found that when wanting to call user data it sometimes helps to add [[!Profile]] to the page and call it something like this:

          [[!Profile]]
          <p>Hello [[+fullname]]</p>


          Hope that helps.

          • discuss.answer
            • 45189
            • 35 Posts
            Okay, I figured it out.

            I finally noticed that it wasn't displaying correctly on pages I had already visited before I logged in, but was fine on pages I hadn't visited yet (until I logged out, then it was chaos everywhere, but anyway...)

            I had this stuff in a chunk on each page, so I called the chunk uncached [[!$chunk]] and it works now!


              • 30912
              • 463 Posts
              Ah the joys of the cache (also the bane of my existence)

              Glad you got it sorted.