Search code examples
phpdrupaldrupal-7drupal-modulesdrupal-views

How to list users by role on page?


I have many user roles on my site.

All users have profile information(custom fileds added).

In a page I want to show 3 type of roles users like like

Role1 :

picture |  name | email | phone no

.....
.....

Role2 :

picture |  name | email | phone no

.....
.....


Role3 :

picture |  name | email | phone no

.....
.....

Using view(Filter) to we can list users by role or anything else but i want to show 3 roles based users with above custom format.

Do we have option like this view? or Can i create 3 views for each role and finally merge it? or Do i want to write custom code?


Solution

  • In the Advanced section of the view, click to add new Contextual filters then choose User: Roles

    Now you can list the users filtered by the Role ID.

    like: users-page/2 will list users who have authenticated user role, users-page/3 will list users who have administrator role, and so on.

    Update 1:

    In the section Configure contextual filter: User: Roles, open More fieldset in the bottom.

    Then access the page like users-page/3+4 will list users who have administrator role and the role id 4.

    Update 2:

    Add the roles to the fields and check Exclude form display. Then under Format -> Settings select Grouping field to Roles.