使用sitecore查询检索项目

5 sitecore sitecore6

在使用xpath构建器的入门工具包中,如何从Home项目下的"Site Section"模板中获取所有继承的项目?

当我运行以下内容时:

/sitecore/content/home/*[@@templatekey='product section'] 
Run Code Online (Sandbox Code Playgroud)

返回/sitecore/content/Home/Products一个有意义的项目,但是,以下内容不会返回任何内容:

/sitecore/content/home/*[@@templatekey='site section'] 
Run Code Online (Sandbox Code Playgroud)

我正在尝试做的是使用asp.net web控件而不是xslt从继承"Site Section"模板的项目构建菜单.

有任何想法吗?

谢谢,塔雷克

**更新

提供有关该问题的更多信息:

项目/sitecore/content/Home/Products具有模板/sitecore/templates/Starter Kit/Site Sections/Product Section,其基本模板为/sitecore/templates/Starter Kit/Item Types/Site Section

如果我想要Home下的产品和参考(类似于产品)项目,我将运行以下查询:

/sitecore/content/home/*[@@templatekey='product section' or @@templatekey='references section']
Run Code Online (Sandbox Code Playgroud)

有没有办法让Home下的项目以Site Section作为基本模板.在xslt中有一个方法sc:GetItemsOfType('site section',$home/item)可以做到这一点.

**答案

var homeItem = Sitecore.Context.Database.GetItem(Sitecore.Context.Site.StartPath);
var siteSectionItems = new List<Item>();

foreach (Item item in homeItem.Children)
{
    var itemTemplate = TemplateManager.GetTemplate(item);

    if (itemTemplate.InheritsFrom("Site Section"))
        siteSectionItems.Add(item);
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*ino 5

//在查询中使用将使其递归到/仅与直接子项相同的位置.这会对性能产生影响.

/sitecore/content/home//*[@@templatekey='site section'] 
Run Code Online (Sandbox Code Playgroud)

还有,不应该@@templatename而不是@@templatekey吗?

/sitecore/content/home//*[@@templatename='site section']
Run Code Online (Sandbox Code Playgroud)


小智 5

var homeItem = Sitecore.Context.Database.GetItem(Sitecore.Context.Site.StartPath);
var siteSectionItems = new List<Item>();

foreach (Item item in homeItem.Children)
{
    var itemTemplate = TemplateManager.GetTemplate(item);

    if (itemTemplate.InheritsFrom("Site Section"))
        siteSectionItems.Add(item);
}
Run Code Online (Sandbox Code Playgroud)