If you're referring to an actual "SelectOne" dropdown, you'll need to change your property and create a selection factory to drive the dropdown's values.
Refer to this documentation: https://docs.developers.optimizely.com/content-management-system/v11.0.0-cms/docs/single-or-multiple-list-options
We don't want to use hard coded values. We want to utilize the categories section under the assets pane. We want to avoid because this item might change.
You don't have to use hard-coded values. Just pull in the list of facets using IContentLoader in your selection factory, and return a list of ISelectItem where the text is a friendly display name of the facet and the value is the ID of the CategoryData.
You can use what Chris has mentioned above. Here is an example.
Looks like you are using Geta Categories. You can pull the list using content loader or some other manner. You can use site settings to set the root of the categories where you want to pull the list for the drop down. And in the selection factory you can pull the list using the node from the site settings.
[CultureSpecific]
[Display(
Name = "Country",
Order = 10)]
[SelectOne(SelectionFactoryType = typeof(GeolocationCountrySelectionFactory))]
public string Country { get; set; }
Here is the code for selection factory. Following is just an example. You can pull the list from some different source or categories etc.
[SelectionFactoryRegistration]
public class GeolocationCountrySelectionFactory : ISelectionFactory
{
private readonly ICountryManager _countryManager;
public GeolocationCountrySelectionFactory(ICountryManager countryManager)
{
_countryManager = countryManager;
}
public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
{
return _countryManager.GetCountries()
.Select(country => new SelectItem {Text = country.Name, Value = country.Code}).Cast<ISelectItem>().ToList();
}
}
I have a faucet and faucet folder for Sample Banners like this:
[ContentType(DisplayName = "Sample Banner Categories Facet", GUID = "xxx--xxx-xxx-xxx-xxx",
Description = "Sample Banner Categories Facet")]
[AvailableContentTypes(Availability.Specific, Include = new[] { typeof(SampleBannerCategoriesFacet) })]
public class SampleBannerCategoriesFacet : CategoryData
{
}
[ContentType(DisplayName = "Sample Banner Categories Facet Folder", GUID = "xxxx-xxxx-xxxx-xxx-xxx",
Description = "Sample Banner Categories Facet Facets")]
[AvailableContentTypes(Availability.Specific,
Include = new[] { typeof(SampleBannerCategoriesFacet), typeof(SampleBannerCategoriesFacetFolder) })]
public class SampleBannerCategoriesFacetFolder : CategoryData
{
[Editable(false)] public new virtual bool IsSelectable { get; set; }
public override void SetDefaultValues(ContentType contentType)
{
base.SetDefaultValues(contentType);
IsSelectable = false;
}
}
What I am trying to achieve is I have to populate the Sample banner categories from CMS as a "Heading" dropdown. My original "Heading" property was like this :
[CultureSpecific]
[Required]
[Display(Name = "Heading", GroupName = SystemTabNames.Content, Order = 10)]
public virtual string Heading { get; set; }
and I changed the string to ContentReference and added [AllowedTypes(typeof(SampleBannerCategoriesFacet))].
[CultureSpecific]
[Required]
[AllowedTypes(typeof(SampleBannerCategoriesFacet))]
[Display(Name = "Heading", GroupName = SystemTabNames.Content, Order = 10)]
public virtual ContentReference Heading { get; set; }
But I couldn't able to get the categories I added in CMS to populate as dropdown.