Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Aniket
Apr 27, 2018
  5818
(2 votes)

Dynamic Drop down list editable by content authors using ISelectionFactory & Property List

On one of my recent projects, we wanted the ability for content authors to manage a list of items in the dropdown through the CMS. Though, it's simple to create a list of items that can be retrieved from a constants class or an appsetting.config, it does require developer to make that change. This also means there needs to be a deployment to production for a simple name/value change in a dropdown.

To get around this standard implementation, we implemented a simple Property List on the Start Page and referenced the property in the ISelectionFactory implementation to get the key value pair.

The dropdown list can now be managed by the content authors without relying on the developer to make a change.  

Here's the code:

 public class AccountPropertiesFactory : ISelectionFactory
    {
        public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
        {
            var contentRepository = ServiceLocator.Current.GetInstance<IContentLoader>();
            var startPage = contentRepository.Get<StartPage>(ContentReference.StartPage);

            var selectItems = new List<SelectItem>();

            foreach(var accountProperty in startPage.AccountTypePropertyList)
            {
                selectItems.Add( new SelectItem()
                    {
                        Text = accountProperty.Text,
                        Value = accountProperty.Text
                    }
                );
            }

            return selectItems.ToArray();
        }
    }
Apr 27, 2018

Comments

Praful Jangid
Praful Jangid Nov 20, 2020 01:14 PM

Thanks Aniket

You saved my day...

Please login to comment.
Latest blogs
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog