Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Thomas Krantz
Apr 20, 2011
  5335
(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
Optimizely CMS Developer Tools for macOS

Running Optimizely CMS on macOS presents unique challenges, as the platform was traditionally primarily designed for Windows environments. However,...

Tomek Juranek | Mar 15, 2025

Removing a Segment from the URL in Optimizely CMS 12 using Partial Routing

Problem Statement In Optimizely CMS 12, dynamically generated pages inherit URL segments from their container pages. However, in certain cases, som...

Adnan Zameer | Mar 14, 2025 |

Optimizely Configured Commerce and Spire CMS - Figuring out Handlers

I recently entered the world of Optimizely Configured Commerce and Spire CMS. Intriguing, interesting and challenging at the same time, especially...

Ritu Madan | Mar 12, 2025

Another console app for calling the Optimizely CMS REST API

Introducing a Spectre.Console.Cli app for exploring an Optimizely SaaS CMS instance and to source code control definitions.

Johan Kronberg | Mar 11, 2025 |