Thomas Krantz
Apr 20, 2011
  5760
(1 votes)

Custom property for selecting Visitor Groups

This custom property will render a checkbox list of all visitor groups, allowing multiple selections.

image 

Add a reference to EPiServer.ApplicationModules.

using EPiServer.Personalization.VisitorGroups;
 
namespace MySite.Website.Plugins.SpecializedProperties.VisitorGroups
{
    [PageDefinitionTypePlugIn(DisplayName = "Visitor Group selection")]
    public class PropertyVisitorGroups : PropertyMultipleValue
    {
        public override IPropertyControl CreatePropertyControl()
        {
            return new PropertyVisitorGroupsControl();
        }
    }
 
    public class PropertyVisitorGroupsControl : PropertySelectMultipleControlBase
    {
        protected override void SetupEditControls()
        {
            var repository = new VisitorGroupStore(DynamicDataStoreFactory.Instance);
            var list = repository.List()
                .OrderBy(v => v.Name)
                .Select(v => new ListItem(v.Name, v.Id.ToString())
                        {
                            Selected = ((PropertyMultipleValue) PropertyData).IsValueActive(v.Id.ToString())
                        })
                .ToArray();
 
            EditControl.Items.AddRange(list);
        }
    }
}
Apr 20, 2011

Comments

Please login to comment.
Latest blogs
The future of Content: Introducing Optimizely CMS 13

Optimizely In the rapidly evolving landscape of digital experience, the "monolithic vs. headless" debate is being replaced by a more sophisticated...

Aniket | May 6, 2026

Hide built in scheduled job from the admin UI

Ok so this probably goes into the not so useful section but late last night I got a veery strong feeling that all projects I am  involved with have...

Per Nergård (MVP) | May 6, 2026

Optimizely SaaS CMS Developer Certification Exam

The Optimizely SaaS CMS Developer Certification is an industry-recognized credential for developers and architects who build scalable, composable...

Megha Rathore | May 5, 2026

Piwik PRO Connector for Optimizely CMS — Now on NuGet (and Yes, It Speaks Both 12 and 13)

Analytics has spent the last decade living in another tab — and what's in that tab usually isn't the full story. Between consent requirements,...

Allan Thraen | May 4, 2026 |

A First Look at Optimizely Remote MCP Server for Experimentation

Optimizely just released a Remote MCP Server for Experimentation and I've been trying it out to see what it can do. If you don't know, MCP (Model...

Jacob Pretorius | May 1, 2026

Promoted and Certified

What a busy week

Andy Blyth | May 1, 2026 |