We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • There are two ways to do the same thing. Using the Personalize snippet:
      [[!Personalize? &yesChunk=`yesChunk` &noChunk=`noChunk` &allowedGroups=`Group`]]
    

    Using an Output Modifier:
    [[[[+modx.user.id:ismember=`Group`:then=`$yesChunk`:else=`$noChunk`]]]]
    

    Pros, cons, any thoughts?

    The first con I can see to the Output Modifier method is that you can only check for one group at a time. If there are multiple groups involved, then you'd be better off using the Personalize snippet. Output Modifiers do have an "or" clause, but using it would quickly become more trouble than it's worth.
      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
      • 36996
      • 211 Posts
      For me, the personalize snippet has better structure and is more readable.
      The question is, which one is faster?
      • I suspect the Personalize snippet, but I doubt if there's really much of a measurable difference with just one group.
          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
        • Here's the actual code for the output modifier, and it does look like you can use a comma-delimited list of groups; actually the docs even say "group(s)."
                                  case 'ismember':
                                  case 'memberof':
                                  case 'mo': /* Is Member Of  (same as inrole but this one can be stringed as a conditional) */
                                      if (empty($output) || $output == "&_PHX_INTERNAL_&") {
                                          $output= $this->modx->user->get('id');
                                      }
                                      $grps= (strlen($m_val) > 0) ? explode(',', $m_val) : array ();
                                      /** @var $user modUser */
                                      $user = $this->modx->getObject('modUser',$output);
                                      if ($user && is_object($user) && $user instanceof modUser) {
                                          $condition[]= $user->isMember($grps);
                                      } else {
                                          $condition[] = false;
                                      }
                                      break;
          
            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