We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46971
    • 33 Posts
    I want to show some content (maybe one section or some text) of a page only to logged in users. How do I make it possible?

    I am thinking of something like:
    modx.user.id:isloggedin= `HTML Code`

    or maybe any solution with a chunk where I put the HTML Code in. Help? smiley
      • 46971
      • 33 Posts
      Okay, some minutes later I finally found a solution for short texts.
      Hope it's still a good way:

      [[!+modx.user.id:eq=`0`:then=``:else=`<p class="small">Some Text</p>`]]


      But this only works for short texts/content. What if I want to put several lines of HTML to the "else"? What if I want to make a whole section of content visible to the logged in user? What is the solution for this case?
        • 17301
        • 932 Posts
        The above solution will also work well for multi html lines or chunks. You could alternatively create a snippet that will show chunk A or chunk B depending on if the user is logged in or not.
          ■ email: [email protected] | ■ website: https://alienbuild.uk

          The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
          • 46971
          • 33 Posts
          Ah, true. I just need to put in the chunk placeholder into the else statement? Sounds quite logical. But multiple html lines (with sections, divs, classes, etc) are not shown with syntax highlights (with extra: ace), when placed into the else statement. So chunks would be the better choice, I guess.
            • 3749
            • 24,544 Posts
            You might look at the Personalize snippet, which shows different chunks to logged-in and not-logged-in users.

              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting