Question

I have a data template which has a DropList field. I want the data source to come from two Sitecore folder items.

Is there anyway to define multiple sources for a droplist?

Était-ce utile?

La solution

Not in the standard drop list field, but it shouldn't be too difficult to create a custom sitecore field based on the Droplist that takes 2 parameters from the source field.

This is a good resource for creating custom controls: http://sitecorejunkie.com/2012/12/28/have-a-field-day-with-custom-sitecore-fields/

The droplist control uses Sitecore.Shell.Applications.ContentEditor.ValueLookupEx for its control. So you could create a new control that inherited from that and override the GetItems() method to read items from your source

The current one looks like this:

protected override Item[] GetItems(Item current)
{
  Assert.ArgumentNotNull((object) current, "current");
  using (new LanguageSwitcher(this.ItemLanguage))
    return LookupSources.GetItems(current, this.Source);
}

so you could make the source have 2 guids/paths split by a pipe (|)

protected virtual Item[] GetItems(Item current)
{
  Assert.ArgumentNotNull((object) current, "current");
  using (new LanguageSwitcher(this.ItemLanguage))
  {
    var sourceList = this.Source.Split('|');
    var items = LookupSources.GetItems(current, source[0]).ToList();
    items.AddRange(LookupSources.GetItems(current, source[1]));
    return items.ToArray();
  }
}
  • Disclaimer - this code is untested, but should point you in the right direction.

Autres conseils

Why not try using Sitecore Query to set the locations and split with AND for both folders perhaps?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top