Hide content sections for users with multiple user roles?

Kayla Johnson asked on April 16, 2018 16:38

We have some pages set up on our client's intranet that have 2 Text web parts - one is shown to users with the International user role, and some is shown to those with the US user role since the copy needs to vary slightly between the 2. But it's not sufficient enough to have separate pages.

However, because of this setup, those with both International and US user roles (i.e. the company's executive team users) are seeing both web parts. Is there a way we can write some conditional logic to hide one of the web parts if the user has both roles?

Correct Answer

Zach Perry answered on April 16, 2018 17:00

Use a macro like this in the visibility condition of the web part.

{%MembershipContext.AuthenticatedUser.IsInRole("International") && !MembershipContext.AuthenticatedUser.IsInRole("US") |(identity)GlobalAdministrator%}

0 votesVote for this answer Unmark Correct answer

Recent Answers

Suneel Jhangiani answered on April 16, 2018 16:59

Should be quite easy since you can set the Visibility of the first web part to those that are in the international role. Then set the visibility of the second web part to those in the US role except when they are not in the International role.

Something like:

If (User.IsInRole("US") && !User.IsInRole("International"))
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.