We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13438
    • 16 Posts
    How can I display the name of the resource group a user is from?
    I have 2 resource groups and I would like to display the resource group name in their profile.

    <div>
    <label><strong>Username:</strong><label>[[+username]]
    <label><strong>Email:</strong><label>[[+email]]
    <label><strong>Member Status:</strong><label>[[+group]]

    </div>

    Everything works but the group tag.
    Any ideas and thank you for your time.

      • 3749
      • 24,544 Posts
      Erm ... Users don't belong to Resource Groups. They belong to User Groups. Because they can belong to more than one User Group, no simple tag will display a Group for them.

      Users can have a "Primary Group," but it's stored as a group ID rather than a name, so a custom snippet could display that as well.
        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
        • 13438
        • 16 Posts
        Quote from: BobRay at Nov 13, 2015, 12:28 PM
        Erm ... Users don't belong to Resource Groups. They belong to User Groups. Because they can belong to more than one User Group, no simple tag will display a Group for them.

        Users can have a "Primary Group," but it's stored as a group ID rather than a name, so a custom snippet could display that as well.

        Bob, thank you for your time. I am on the side of UX/UI not to much into snippet programming. But i am assuming a simple echo on the snippet will do the work? any links for examples that you can share.

        Thank you
          • 3749
          • 24,544 Posts
          This should do it for the current user:

          $groupId = $modx->user->get('group');
          $group = $modx->getObject('modUserGroup', $groupId);
          $name = $group->get('name');
          
          if (empty($name)) {
             $name = 'No Primary Group';
          }   
          
          $modx->setPlaceholder('group', $name);
          


          If you're making a list of users with your own snippet, it would depend on the code.



          [ed. note: BobRay last edited this post 10 years, 11 months ago.]
            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
            • 4172
            • 5,888 Posts
            I think, it should be

            $modx->setPlaceholder('group', $name);
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 3749
              • 24,544 Posts
              Definitely. Thanks Bruno.

              Fixed above.
                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