What's the difference between Sitecore Droplink and Droplist in Custom Item Builder?

I know both fields only contain individual items in Sitecore, but Droplinks keeps the item ID, while Droplists keep the item's display name.

In the coding part, when we get the Droplist value through the custom item generator class, it provides ListItems. But, as I mentioned above, droplists also contain individual items. So what is the difference and why does the custom item-item class provide list items in the case of Droplists? Is this a bug in the custom item generator?

What is the main difference between both fields?

+3


source to share


3 answers


This is a bug in the configuration of the custom element generator patch, CustomItem.config

In this file, it maps the DropList field type to a multi-sheet wrapper that exposes the property ListItems

:

<FieldMapping fieldType="Droplist">CustomMultiListField</FieldMapping>

      



You have to change this part of the config to reverse the text that looks like this:

<FieldMapping fieldType="Droplist">CustomTextField</FieldMapping>

      

+2


source


You are understanding correctly how Sitecore stores values ​​for these two different field types. I don't know the details of the code or module you are using, but here are some code examples explaining how you can do it.

dropdown list

Stores the name of the selected item in the box. Note that the dropdown in the Sitecore Content Editor displays the display name of the items, but still uses the item name internally. If you want to get the selected item, you can do it like this:

Item sourceItem = //code here to get the item selected as the *source* of the template field
Item item = Sitecore.Context.Item;
string selectedName = item["YourDroplistFieldName"];
Item selectedItem = sourceItem.Children[selectedName];

      

Droplink



Stores the ID of the selected item in the box. Use the following to retrieve this item:

Item item = Sitecore.Context.Item;
LinkField field = item.Fields["YourDroplinkField"];
Item selectedItem = field.TargetItem;

      

Note. To see how Sitecore stores fields internally, you can select the View toolbar and check the Raw Values ​​checkbox (in the Content Editor).

I usually almost always use the droplink field above the dropper , except when you only need to use the name of the selected item.

+7


source


As you noticed Droplink

, it Droplist

stores the element's identifier, and only stores the string representation of the element (element name). When you use Droplist it is not possible to retrieve the actual item. That is, when using Droplink, you have the option to get the TargetItem. Also when renaming the item and previewing the raw values, you can see that in the case of using Droplist, the item selection is no longer available, but the value is somehow saved.

+2


source







All Articles