Developer forum

Forum » Templates » Looping group and users in those groups

Looping group and users in those groups

Jens Mouritzen
Jens Mouritzen
Reply

I'm having a hard time making a loop work inside a loop (see picture 1). I dont know if this is possible at all (it should be).
The looping should be like this:

Group 1
   User 1
   User 2
   User 3

Group 2
   User 4
   User 5
   User 6

Do we maybe need LINQ for this ?

picture1.png

Replies

 
Nicolai Pedersen
Reply

Hi Jens

I am affraid you cannot - simple anyways. Users can be in many groups - so that would potentially give the same users many times.

You can create a group structure in Razor you can use the AllGroups loop and look at the UserManagement:Group.ID and the UserManagement:Group.ParentID tags to create the tree structure using a dictionary and some rendering logic.

You can use the API to get users in a group. So in the groups loop, create an instance of Dynamicweb.Security.UserManagement.Group using the groupid - and then call the Users property :

https://doc.dynamicweb.com/Default.aspx?ID=8258#article=fb8104ba-1f1f-2e8d-8f33-3afcecb5d39e

Be careful about performance as this is a lazy call on the database.

BR Nicolai

 

You must be logged in to post in the forum