We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18913
    • 654 Posts
    Okay, another little problem has cropped up...

    I have a Wayfinder menu with a title "Member Login" which - predicatably - takes one to a place to log in. Upon successful login, there are pages available that would not otherwise be seen.

    Still visible, however, is the "Member Login" page. For real estate reasons, I’d like to keep this as a page in the Wayfinder menu. But I’d like it’s title to change to "Logout" for example if the user has logged in.

    Now, being clever, I tried entering this as the page’s title :
    [!Personalize? &yesChunk=`LoggedInYes` &noChunk=`MB_LoggedInNo`!]

    This seemed to work on a local install, but when my partner tried it on a live site, the status wouldn’t change.

    And I seemed to recall trying something similar before (putting a chunk or snippet call directly in for the value of a document field) with mixed results.

    Leading me to think that this is really not a good practice.

    Soooo... Can anyone recommend a solution? Or is this in fact a legit approach?

    Thanks (again),
    MattC
      • 18913
      • 654 Posts
      Upon further review (actually, with the benefit of having seen the Sample Data loaded), it would seem that using a TV like
      loginName

      which is defined as an EVAL
      would do the trick.
      MattC
        • 18913
        • 654 Posts
        Okay, I might have jumped the gun on this a bit.

        I get the idea of using a TV to change the pagetitle based on status. Got that working.
        And I got a static link to work with the Personalize snippet. It changes it’s text and the correct behaviour is triggered on clicking. Got that.

        But what I really need (scratch that. What the client wants ...) is for that same behaviour (i.e. the logging out action) to be trigged automatically when the page is clicked on in the Wayfinder menu. I can’t see how to set this dynamically. Maybe I’m just to freakin’ exhausted.

        Anyone with ideas?
        Thanks,
        MattC
          • 18913
          • 654 Posts
          This may be a solution. I tried it on a local install with Evo 1.0.2 and it seemed to work...

          The scenario is that I have a page which contains a call to WebLogin. I want the title to be dynamic depending upon the web user’s login status. That is, in a Wayfinder menu I want it to say "Login" if the user is not logged in and "Logout" if the user is logged in. As importantly, if they are logged in and click on the menu item, I not only want the page brought up but I want them automatically logged out.

          In my test, I created a document with the WebLogin call and noted it’s id number. In this case it was 139.

          I created two template variables. The first TV was called "loginName" and is taken from the material installed when one selects "Install Sample Data" when doing the MODx installation. Specifically, it is a text TV with a default value of
          @EVAL if ($modx->getLoginUserID()) return 'Logout'; else return 'Login';


          The second TV I called "loginAction". It is also a text TV with a default value of
          @EVAL if ($modx->getLoginUserID()) return '<a href="[~139~]&webloginmode=lo">Logout</a>'; else return '<a href="[~139~]">Login</a>';


          Turning now to the document that I created above (the one with id=139), I put
          [*loginName*]

          in the field "Title" and I put
          [*loginAction*]

          in the field "Menu title".

          This would appear to generate the behavior I need. If anyone sees any problems with this, I’d appreciate hearing about it.

          UPDATE : This worked with FURLs on and no suffix attached to the link generated. No doubt this will bust spectacularly if that’s not the case ...
          EDIT : "?" should be "&" I think ...

          Thanks for listening,
          MattC
            • 3349
            • 126 Posts
            Hi Matt

            Looking to do the same, does your solution work ok?

            Thanks

            bS
              • 18913
              • 654 Posts
              I seem to recall the approach working ok. But I also seem to recall the client changing the layout after that. So I’m not sure at the moment if my partner ended up implementing it.
              Matt