We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Let’s back up. List all the user groups and which chunks each should see.
      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
      • 36760
      • 136 Posts
      Sure, that might clear things up a little more. The client is changing a lot of things on me, so some of this has changed since I first made this thread. Though the idea remains the same. Thank you for all the help.

      (anonymous) (assuming this is the user group used for people not logged in)
      Should see: $paidContentPreview

      members-free
      Should see: $paidContentPreview

      member-paid, college-jr-paid, hs_paid, etc. (Same as below, I have a handful of similar groups that fall into the same category for this)
      Should see: $customizedStrategySectionPreview
      Should not see: $paidContentPreview

      college_junior_max, college_junior_conservative, etc. (I have about 20 similar groups that, for the sake of this, fall into the same category)
      Should see: $strategyOutlinesPermissionBased
      Should not see: $paidContentPreview, $customizedStrategySectionPreview

      Then to put it into context, my goal is to create a single outline page with all the different articles/pages that will change as the user progresses from free, to paid, to having picked a strategy. Basically going from showing preview titles and snippets of the articles, to having actual links to the articles. Most of it works automatically with Wayfinder and the permissions, but I’ve had to use these chunks for some of it.

      By the time a user gets to the third tier of user groups, they will be a member of college_junior_max, college-jr-paid, member-paid, and members-free (or some groups along those lines). It sounds complicated, but in the context of the site it seemed to make the most sense to me and the client. It just complicates some other things (like with what we’re trying to do with the chunks).

      Hopefully that helps some.
        • 3749
        • 24,544 Posts
        If you’ve described it correctly and I’m understanding you, this should do it:


        <?php
        if ($modx->user->isMember('college_junior_max,college_junior_conservative,etc.') {
        
             $output =  $modx->getChunk('strategyOutlinesPermissionBased');
        
        } elseif ($modx->user->isMember('member-paid,college-jr-paid,hs_paid,etc.') {
        
             $output =  $modx->getChunk('customizedStrategySectionPreview');
        
        } else {
        
             $output =  $modx->getChunk('paidContentPreview');
        }
        
        return $output;
        


        Note that there are no spaces in the comma-separated lists of groups. Replace the "etc."s with the other group names.

        If the user is a member of one of the groups in the first if statement, the other sections won’t execute. If they’re a member of the second list, the third part won’t execute, so each set of groups should see their own chunk.

        If you need to show more than one chunk to one class of members, just add lines like this to their section:

        $output .= $modx->getChunk('SomeOtherChunk');

          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
          • 37044
          • 68 Posts
          I have a quick extension of this question - based around this thread as well (https://forums.modx.com/?action=thread&thread=32601)

          I have two member groups 'group-a' and 'group-b'

          I want to write a snippet that will ultimately do the do a php if else / or switch functionality. I know people have recommended the switch extra (http://modx.com/extras/package/switch) before.

          So I what I want to do is:

          if user is logged in and part of 'group-a' show 'chunk-a', if user is logged in and part of 'group-b' show 'chunk-b' else show 'chunk-default'

          I have tried a number of iterations but cant seem to get the syntax right

          Any help appreciated.
            • 10208 ☆ A M B ☆
            • 1,780 Posts
            I'm trying to implement this to display one chunk for logged in users, and one for anonymous. There are three user groups to display logged in username with login.profile.

            When I insert the loggedInUser snippet into the chunk, the front end goes blank. Nothing in the source, white/blank display. Removing the snippet returns the display, all is well.

            I've stared at this far too long. Why would a snippet cause a blank display? For whatever it's worth, this chunk is in the template, so the blankness is site wide.

            Thank You for all keen eyes and candid criticism :~}


            loggedInUser snippet:
            <?php
            if ($modx->user->isMember('cswaPrivate,liloMembersPrivate,subscribers') {
             
                 $output =  $modx->getChunk('loggedInUser');
              
            } else {
             
                 $output =  $modx->getChunk('anonUser');
            }
             
            return $output;


            main chunk with offending snippet:
            <div class="row">
            	<div class="page curltl">
            		[[!Wayfinder? &startId=`[[!UltimateParent]]` &displayStart=`1` &rowTpl=`rowTpl` &innerTpl=`innerTpl`]]
            	</div>
                    [[!Profile]]
            	<div class="row">[[!loggedInUser]]</div>
            	<div class="row">[[!Login? &loginTpl=`lgnLoginTpl` &logoutTpl=`lgnLogoutTpl` &errTpl=`lgnErrTpl` &loginResourceId=`31` &logoutResourceId=`36`]]</div>
            	<div class="row search">
            		<hr><div class="two columns"><p>Search</p>
            	</div>
            		<div class="nine columns">[[!SimpleSearchForm? &tpl=`SearchFormTpl` &landing=`12` &hideMenu=`1`]]<hr>
            		</div>
            	</div>
            </div>
              Frogabog- MODX Websites in Portland Oregon
              "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
              Having server issues? These guys have MODX Hosting perfected - SkyToaster
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Try
              $user->isMember('cswaPrivate,liloMembersPrivate,subscribers')


              http://rtfm.modx.com/display/revolution20/modUser.isMember

              It might be enlightening to check the Manager's error log (Reports -> Error Log)
                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
                • 10208 ☆ A M B ☆
                • 1,780 Posts
                I tried a few options, it still produces nothing. The only errors I can produce with the following snippet, seem to be after I attempt to navigate from the home page (another template) to any of the inner pages.

                Errors

                From last night:
                [2012-08-18 13:10:23] (ERROR @ /lilomdx/connectors/element/index.php) Error caching lexicon topic lexicon/en/core/default
                [2012-08-18 13:57:22] (ERROR @ /lilomdx/connectors/element/index.php) Error caching action map mgr/actions


                From today:
                [2012-08-18 17:28:11] (ERROR @ /lilomdx/index.php) Error caching script elements/modplugin/18
                
                [2012-08-18 17:37:07] (ERROR @ /lilomdx/connectors/element/propertyset.php) Error caching lexicon topic lexicon/en/core/default
                [2012-08-18 17:37:07] (ERROR @ /lilomdx/connectors/element/index.php) Error caching action map mgr/actions
                [2012-08-18 17:41:19] (ERROR @ /lilomdx/connectors/layout/modx.config.js.php) Error caching lexicon topic lexicon/en/core/resource


                Reloading or direct access to an inner url produces no errors. Navigating from the home page, or navigating from a working page after removing the snippet produces errors.

                I've tried both:
                if ($user->isMember('cswaPrivate,liloMembersPrivate,subscribers') {
                


                and:

                if ($user->isMember(array('cswaPrivate,liloMembersPrivate,subscribers')) {
                 
                  


                The above does not throw any errors, no matter how I access an inner page.
                  Frogabog- MODX Websites in Portland Oregon
                  "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
                  Having server issues? These guys have MODX Hosting perfected - SkyToaster
                  • 10208 ☆ A M B ☆
                  • 1,780 Posts
                  Should I take this to a new thread? This is marked solved, but it's unsolved for me.

                  I accidentally inserted this snippet into another page, (got crazy with ctrl+a) and of course it did the same thing.
                    Frogabog- MODX Websites in Portland Oregon
                    "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
                    Having server issues? These guys have MODX Hosting perfected - SkyToaster
                    • 3749
                    • 24,544 Posts
                    I just noticed, the first line of your snippet needs another ) at the end. It's a mistake I make all the time in the forums (on real code, PhpStorm points it out for me).


                    ------------------------------------------------------------------------------------------
                    PLEASE, PLEASE specify the version of MODX you are using.
                    MODX info for everyone: http://bobsguides.com/modx.html
                      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
                      • 10208 ☆ A M B ☆
                      • 1,780 Posts
                      Thanks Bob,

                      I tried:

                      <?php
                      if ($modx->user->isMember('cswaPrivate,liloMembersPrivate,subscribers') ){
                        
                           $output =  $modx->getChunk('loggedInUser');
                         
                      } else {
                        
                           $output =  $modx->getChunk('anonUser');
                      }
                        
                      return $output;


                      It still returns a blank result.

                      I also tried this, adding yet another closing ) to match every opening (:

                      if ($modx->user->isMember(array('cswaPrivate,liloMembersPrivate,subscribers'))) {
                       
                           $output =  $modx->getChunk('loggedInUser');
                        
                      } else {
                       
                           $output =  $modx->getChunk('anonUser');
                      }
                       
                      return $output;


                      Same result. I don't get why it'd gork every page using that template rather than just not work.
                        Frogabog- MODX Websites in Portland Oregon
                        "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
                        Having server issues? These guys have MODX Hosting perfected - SkyToaster