是的,从当前上下文中,您可以检索父项(及其所有字段),如下所示:
MultilistField parentMultilistField = Sitecore.Context.Item.Parent.Fields[...];
var parentTitle = Sitecore.Context.Item.Parent["Title"];
Run Code Online (Sandbox Code Playgroud)
...或使用递归甚至Sitecore查询向上遍历多个级别:
var parentItem = Sitecore.Context.Item.Axes.Select.SelectSingleItem("./ancestor-or-self::*[@@templatekey = 'sometemplate']");
Run Code Online (Sandbox Code Playgroud)
如果您使用的是玻璃映射器,则可以使用[SitecoreParent]或[SitecoreQuery(...)] attribue来装饰属性,如下所示:
[SitecoreParent]
public virtual MyBaseItem Parent { get; set; }
[SitecoreQuery("./ancestor-or-self::*[@@templatekey='sometemplate']", IsRelative = true)]
public virtual MyBaseItem RootItem { get; set; }
Run Code Online (Sandbox Code Playgroud)