We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13736
    • 345 Posts
    Amazing. that does work. Care to explain how its working? What in that chunk is telling the Weblogin snippet to swap messages based on login status?

    And second. Does anyone know if the personalize snippet can display the full name if available rather than a user ID?

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      It’s the [+personalize+] placeholder. The personalize snippet loads its output into the placeholder with that name (if you specified that option in the snippet call), and it gets displayed wherever you put the placeholder. You can even have the placeholder in more than one place, and use it in any chunk, template, or document content you like.

      The snippet could display anything you like. It uses the modx class function
      $test = $modx->getLoginUserName();

      which returns the $_SESSION[’webShortname’].

      But it could grab the value desired directly from the SESSION all by itself.
      $test = $_SESSION['webFullname']);
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 13736
        • 345 Posts
        And how hard would it be to add a selector to the Personalize snippet so that you could choose which data field it pulled the name from. Or I suppose it could then be address, birthday, or whatever.

          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Well, as it is, it only gets data from the SESSION, so we’re talking some serious database queries here to access two or three tables for the data on the current user. Doable, but I doubt if you’ll see it soon.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 13736
            • 345 Posts
            I guess I don’t understand what the SESSION is. I figured the

            $test = $_SESSION['webFullname']);


            was simply a database field reference that could be changed to any other available field for a web user. And for someone familiar with PHP it would be easy to make a snippet switch that picked which field to grab data from.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              SESSION is an array used by PHP for session persistance, since TCP/IP is a "stateless" protocol. The web server doesn’t know you or anything at all about you from one page request to another, so some means has to be used to maintain your "state" (like if you are logged in and what your login information is) across an entire session of browsing a site.

              PHP sets up a file (by default; this can be changed to other methods of storage) with a random wierd long number type name, and keeps information about you in that file. It puts the session name in a cookie, so that every time you request a page that cookie gets sent as well, and PHP goes and grabs your session file and puts it into the SESSION array, and updates the file with the access time.

              Every now and then PHP checks all the SESSION files in its session file folder, and deletes any that have access times older than a specified amount of time (by default ~22 minutes). That’s what a "session time-out" is all about; if you were logged in and didn’t do anything for ~22 minutes, suddenly you’ll find yourself logged out.

              MODx adds all sorts of goodies to that array, such as your login name, your full name, and your user ID, and PHP writes the new stuff to the file. So a script can get that information from the SESSION array without having to go to the database. But not all information about a user is put into the SESSION array by MODX, so if you wanted other information a script would have to go make database queries. Web user data is kept in five or six different tables. so the queries can get interesting.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 8881
                • 73 Posts
                Quote from: The at May 22, 2006, 08:25 PM

                Hi all. Perhaps this has already been figured out by everybody, but here’s a working example on how to set this up, exactly as jbjones wanted:

                In your template, call the snippets:
                [!Personalize? &ph=`personalize` &message=`Welcome back ` !]
                [!WebLogin? &tpl=`WebLoginTop` !]


                Create the chunk WebLoginTop:
                <!-- #declare:separator <hr> --> 
                <!-- login form section-->
                <a href="[~~]" class="personalizeRegister">Register</a> or <a href="[~~]" class="personalizeLogin">Login</a>
                <hr>
                <!-- log out hyperlink section -->
                [+personalize+] |
                <a href='[+action+]'>[+logouttext+]</a>
                <hr>
                <!-- Password reminder form section -->
                

                Just make sure you actually put the IDs of the Register and Login pages in the chunk.

                I hope that helps, newbies and more advanced users as well. It does take a second to wrap your head around the whole workings of it, but it makes great sense once you get it.
                -Brett

                Hey ummm.. I have done that on my site but for some reason every time I login to the site. After I login it redirects us to the 404 Page. Instead of like the page you were one or the home page. how can I fix that?