We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37984
    • 215 Posts
    Hey all - trying to find a way to output the usergroup of a logged in user on the front end of my site. Currently, I'm just using the Full Name, but would like to be a little less specific. My current code looks like this:

    [[!Profile]][[+fullname]]


    I would like to replace this with something along the lines of this:

    [[!Profile]][[+usergroup]]


    I apologize in advance if this is a stupid question - and for the record, I have tried to shoehorn the Peoples addon into this, but haven't found a way to successfully implement it yet.
      Jesse Couch
      MODX Aficionado, Front-End Designer & Developer
      http://www.designcouch.com
      • 3749
      • 24,544 Posts
      There's no easy way to do it because the user might belong to more than one user group and the information you need is stored in more than one table (none of it in the user or profile tables). It would take a non-trivial custom snippet. If you list the names of of all possible user groups in the snippet tag and each user belongs to only one group, you could sort of cheat by using this code (untested):

      [[!UserGroup? &groups=`group1,group2,group3`]]


      <?php
      $userGroups = explode(',', $scriptProperties('groups'));
      
      $output = 'Not in a group';
      
      foreach ($userGroups as $userGroup) {
      
          if ($modx->user->isMember(trim($userGroup))) {
               $output = $userGroup;
          }
      }
      
      return $output;
      


        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
        • 37984
        • 215 Posts
        BobRay - thanks for your help. I wasn't able to make this work for what I needed (just going to use the fullname field for now), but you've given me some definite food for thought!
          Jesse Couch
          MODX Aficionado, Front-End Designer & Developer
          http://www.designcouch.com