且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Sitecore模板字段中使用下拉列表类型

更新时间:2023-02-11 19:56:01

Droplist类似于Droplink字段类型,因为它们都是下拉列表。Droplist将只存储项目的名称(因此它没有指向该项目的链接),而Droplink存储项目的ID。这意味着,如果您重命名选项或将其移动到内容树中的其他位置,Droplist将不会更新(可能导致链接断开),Droplink将更新。

您可以通过将模板中的Datasource字段设置为某个值来向Droplist添加值(例如,/sitecore/content/Home/CSS/如果您希望将CSS类名存储在该位置)。

您可以使用如下代码访问Droplist

Item item = Sitecore.Context.Item;
string css = item["FieldName"]; // Also possible is item.Fields["Fieldname"].Value;

ADroplink可以这样访问:

string dropDownItemId = item["Fieldname"]; // Or, again, item.Fields["Fieldname"].Value; if you prefer
var cssItem = Sitecore.Context.Database.GetItem(dropDownItemId); // And now you can
// access any fields in this item.

编辑 A good article going into some more detail in the differences between Droplink and Droplist