November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
You could create your own critera, where you check what group the user is part of:
Just implement the IsMatch-method to suit your needs.
Hi Joakim,
The visitor group is criteria the best approach to show/hide content on basis of user group and if your criteria do not match in builtin visitor group then visit the below URL and create own visitor group criteria and applied above the content https://world.episerver.com/documentation/developer-guides/CMS/personalization/example-create-your-own-visitor-group-criteria/
And if you want to display specific content for the only logged-in users then use HttpContext.Current.User and check the user is anonymous or logged In and show/hide content.
Thanks!
If you want to display plain text that differ based on group, you could also do something like this. Create a helper class.
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using EPiServer.Security;
namespace Alloy.Helpers
{
public static class WelcomeUserHelper
{
private static readonly Dictionary<string, string> WelcomeMessages = new Dictionary<string, string>()
{
{ "WebAdmins", "Hey admin!" },
{ "WebEditors", "Hey editor!" }
};
public static string Welcome(this HtmlHelper helper)
{
foreach (var (group, message) in WelcomeMessages.Select(x => (x.Key, x.Value)))
{
if (PrincipalInfo.Current.RoleList.Contains(group))
{
return message;
}
}
return string.Empty;
}
}
}
Add your messages to the top dictionary, and include in your view like this:
@Html.Welcome()
Does that work for you?
If the user is a member of multiple groups included in your configuration, only the first will be shown. Order your groups accordingly, or modify the code to display multiple messages in those cases.
Hi,
What is the best way to display text or content depending on what group an end user is part of?
When a logged in user visits a page, I want to display some text in case they are part of one group, and some other text if they belong to the other group.
I have tried to look at examples about visitor groups, but they usually base the displaying of content on things like location or time of day while I want to go to the backend and check what group the logged in user is part of, and based on that display the right content.
Are visitor groups the way to go or is there some other solution I can read up on?
Thanks!