我正在尝试列出在 Sitecore 的父页面上具有设置模板的项目。到目前为止,我可以为孩子做这件事,但我也想包括孩子的孩子,即父级下的任何内容,如果它有选择的模板,它就可以工作,这是我在 c# 文件中的代码:
lvThing.DataSource = context.Children.Where(x => x.TemplateName == "cool template").ToList<Item>();
lvThing.DataBind();
如果您想要子项下面的项目,则可以使用该项目。Axes.GetDescendants() 方法获取上下文项下的所有项。
然后,您的代码应如下所示:
contextItem.Axes.GetDescendants().Where(x => x.TemplateName == "cool template").ToList();