문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top