SaaS CMS has officially launched! Learn more now.

Aniket
Apr 27, 2018
  5910
(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
Optimizely release SaaS CMS

Discover the future of content management with Optimizely SaaS CMS. Enjoy seamless updates, reduced costs, and enhanced flexibility for developers...

Andy Blyth | Jul 17, 2024 | Syndicated blog

A day in the life of an Optimizely Developer - London Meetup 2024

Hello and welcome to another instalment of A Day In The Life Of An Optimizely Developer. Last night (11th July 2024) I was excited to have attended...

Graham Carr | Jul 16, 2024

Creating Custom Actors for Optimizely Forms

Optimizely Forms is a powerful tool for creating web forms for various purposes such as registrations, job applications, surveys, etc. By default,...

Nahid | Jul 16, 2024

Optimizely SaaS CMS Concepts and Terminologies

Whether you're a new user of Optimizely CMS or a veteran who have been through the evolution of it, the SaaS CMS is bringing some new concepts and...

Patrick Lam | Jul 15, 2024

How to have a link plugin with extra link id attribute in TinyMce

Introduce Optimizely CMS Editing is using TinyMce for editing rich-text content. We need to use this control a lot in CMS site for kind of WYSWYG...

Binh Nguyen Thi | Jul 13, 2024

Create your first demo site with Optimizely SaaS/Visual Builder

Hello everyone, We are very excited about the launch of our SaaS CMS and the new Visual Builder that comes with it. Since it is the first time you'...

Patrick Lam | Jul 11, 2024