November Happy Hour will be moved to Thursday December 5th.

Thomas Krantz
Apr 20, 2011
  5256
(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 SaaS CMS + Coveo Search Page

Short on time but need a listing feature with filters, pagination, and sorting? Create a fully functional Coveo-powered search page driven by data...

Damian Smutek | Nov 21, 2024 | Syndicated blog

Optimizely SaaS CMS DAM Picker (Interim)

Simplify your Optimizely SaaS CMS workflow with the Interim DAM Picker Chrome extension. Seamlessly integrate your DAM system, streamlining asset...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Optimizely CMS Roadmap

Explore Optimizely CMS's latest roadmap, packed with developer-focused updates. From SaaS speed to Visual Builder enhancements, developer tooling...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Set Default Culture in Optimizely CMS 12

Take control over culture-specific operations like date and time formatting.

Tomas Hensrud Gulla | Nov 15, 2024 | Syndicated blog