We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7084
    • 17 Posts
    Is it possible to have the main navigation change completely once a web user has logged in?

    Right now I have this for navigation for the Frontend when someone is NOT logged in:

    Sentai Home
    Industries
    Solutions
    Services
    Platform
    Our Company

    I would like this to change completely once a web user has logged in to:

    Member Home
    New and Events
    Documents & Downloads
    Support
    FAQ and Help
    Contact Us

    I have created a client group and the nav does appear once your logged in but the Frontend navigation is still present. I would like to take that out once a member has logged in.

    Thanks!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Have the two groups of documents in two separate (empty) folders. Use a snippet to determine if the user is logged in or not, returning one ID if the user is not logged in, the other if he is. Use that snippet as the value of the &startId option for your menu.

      The not-logged-in "home" page should be your site’s start page (as set in the configuration).

      Just to be on the safe side, you could have the only content of the two parent folders be the FirstChildRedirect snippet.

        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
        • 7084
        • 17 Posts
        I am very new to MODx, only been working with it for a week now so I please forgive my ignorance...

        When you say 2 group of documents is this something that I need to create in the backend or is this something that I need to create on the server?
        I am just bringing this up because I have been reading in the forums and it seems that folders do not exist anymore in MODx?
        Could you let me know exactly how to create what you mentioned in your post?


        You have mentioned that I need a snippet to redirect the users:

        Use a snippet to determine if the user is logged in or not

        DO you have any examples of a snippet I can use to do this?


        I am also a bit confused on what you mentioned here:

        Just to be on the safe side, you could have the only content of the two parent folders be the FirstChildRedirect snippet.

        Could you elaborate on this please?

        Thanks,
        Denis
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          In MODx when referring to "documents" and "folders", this means in the Manager’s document tree. A "folder" is simply a document that has children; a folder can be an ordinary document or just an empty document to act as an organizing container.

          So this means you’ll create two new documents in the root of the tree, one for the public documents and one for the private documents. Make sure they are set to not show in the menu, or even unpublish them so they won’t be shown in any menus.

          Move all of your public documents into the new document you created for that purpose, and likewise move the private documents. Now when you make a Wayfinder call, for public documents use the ID of the new document you created, and for the private section use the ID of the new document you created to contain the private documents.

          Make a new snippet that has
          if( <check for logged-in user here> ) { 
              $modx->runSnippet('Wayfinder', array('startId' => 'xx', ...) ;
          } else { 
              $modx->runSnippet('Wayfinder', array('startId' => 'yyy', ...);
           }

          Add any other options you want for the Wayfinder snippet calls as ’name’=>’value’, since the Wayfinder function will use those as its arguments in the same way it does the &name=`value` in regular snippet tags. The ’xx’ and ’yy’ will be the ID of the two documents you are using as containers.

          Use this snippet where you would usually put a Wayfinder snippet call.

          If you have any public documents that you do want displayed to the private users, just make a weblink to it in your private folder/container section of the document tree.
            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
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Ok, that code was really bad tongue Here’s an actual working version:
            if( isset($_SESSION['webValidated']) && $_SESSION['webValidated'] == 1) { 
                 return $modx->runSnippet('Wayfinder', array('startId' => '47', ...)) ;
            } else { 
                 return $modx->runSnippet('Wayfinder', array('startId' => '46', ...)) ;
            }


            If you had more than one web group and wanted the menu display to depend on the web group the logged-in user was in, you could check the session for the user’s web groups instead of just checking to see he’s logged in.
              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
              • 4310
              • 2,310 Posts
              I don’t want to step on anyones toes but....
              if the two sets of documents are completely different the solution I used was to:
              create member documents in a separate folder/parent doc
              make them siteadmin pages
              use the standard
              @EVAL if ($modx->getLoginUserID()) return 'Logout'; else return 'Login'; 
              in the loginName TV
              have your Wayfinder menu call for the member parent include
              &startId=`xx`
              where xx is the member parent doc ID
              If someone tries to access the pages directly they get redirected to the login page
              If they login you can send them direct to the member doc with the custom menu by setting the Login Home Id to xx when you set up the member user using the create/edit web user tool in the manager
              MODx offers several ways to achieve the same end result!
              Regards,
              David