Keyword for User Group

(Nick Papadatos) #1

Matrix Version: 6.28


I’m trying to get the the ID of the user group that I’m in.

For instance:
var group = %globals_user_member_groups% returns [12,3456,7895,12345]; but I only want to get the direct parent group ID which is Group 2


Group 1
  Group 2
    John Doe
    Mary Jones 
    Ben James etc

Hopefully I have given enough info


(Kenny Cameron) #2

Something like this should work

Get the parent ID of the current user and then pull the name of the parent ID out, which should be their group. Might be a simpler way, but this seems to work ok for me

(Nick Papadatos) #3

Good one Kenny, thanks

I was over thinking this a tad
I ended up with: %globals_asset_assetid:123456^as_asset:asset_children% which is what I was after
ie; targeting a specific user group and its users

pseudo code: If the logged in user is in this specific group (of sys-admins) then show extra content/tools


(Kieran) #4

The proposed solution may be different if a user is within more than one user group?

(Nick Papadatos) #5

I’m targeting a specific group with the following "%globals_asset_assetid:123456^…
If you’re not in group 123456 then you don’t get extra content no?

(Kenny Cameron) #6

Ah, ok - i have something similar that I adapted from a solution one of the Squiz devs provided us.

 ~ content ~

12345 is the Asset ID of a regular expression – you can add multiple groups here, in the event you want to check a few. If any are a match, it shows the content. Just make sure and surround the Asset ID of your groups with /b \b/

Might be overkill for your needs, but handy for future projects :slight_smile:

(Nick Papadatos) #7

Great! Thanks for sharing Kenny.
Here’s my full solution for this scenario:

 <script runat="server">
      let group  = %globals_asset_assetid:123457^as_asset:asset_children^empty:[]%;
      let user   = "%globals_user_assetid%";
      let html = '';

           if(group.includes(user)) {
              html +=`
                //HTM content specific for sys admins goes here


I’m definitely keeping your solution in my back pocket for that rainy day :slight_smile:

I do wonder wheteher in the regex you can seperate them by pipe so it becomes ‘or’
like so: /\b123\b|/\b12345\b/ etc