C# 模板构建器中站点核心“源”字段的查询符号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12611258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 23:54:11  来源:igfitidea点击:

Query notation for the sitecore 'source' field in template builder

c#asp.netcontent-management-systemsitecoresitecore6

提问by M.R.

I am trying to set the the source field of a template using the query notation (or xpath - whichever works), but none of them seems to be working.

我正在尝试使用查询符号(或 xpath - 以工作为准)设置模板的源字段,但它们似乎都不起作用。

My content tree is a multisite content tree:

我的内容树是一个多站点内容树:

France
--Page 1
----Page1A
-------Page1AA
--Page 2
--Page 3
--METADATA
----Regions

US
--Page 1
----Page1A
-------Page1AA
--Page 2
--Page 3
--METADATA
----Regions

Each site has its own METADATA folder, and I want it so that when adding a page inside each of the main country nodes, I want the values to reflect whatever is in the METADATA of that site. I have two different fields for now - a droplink and a treelistex field. So I thought I can just get the parent item that is a country site, and get the metadata folder for that. When I put the following query in both the fields, I get different results:

每个站点都有自己的 METADATA 文件夹,我希望这样在每个主要国家/地区节点内添加页面时,我希望这些值反映该站点的 METADATA 中的任何内容。我现在有两个不同的字段 - droplink 和 treelistex 字段。所以我想我可以只获取作为国家/地区站点的父项,然后获取元数据文件夹。当我将以下查询放在两个字段中时,我得到不同的结果:

 query:./ancestor::*[@@templatename='CountryHome']/METADATA/Regions/*
  • For the droplink field, I get only the first Region (one item)
  • For the treelistex field, I get the entire content tree
  • 对于 droplink 字段,我只得到第一个区域(一个项目)
  • 对于 treelistex 字段,我得到了整个内容树

I then tried to modify the query a little bit and took the 'query' notation out

然后我尝试稍微修改查询并去掉“查询”符号

 ./ancestor::*[@@templatename='CountryHome']/METADATA/Regions/*

If I go to the developer center/xpath builder, and set the context node to any item underneath the main country site, it returns me exactly what I need, but when I put this in the source, I get the entire content tree in both the cases.

如果我转到开发人员中心/xpath 构建器,并将上下文节点设置为主要国家/地区站点下的任何项目,它会准确地返回我需要的内容,但是当我将其放入源中时,我会在两个项目中都获得整个内容树案件。

Help!

帮助!

采纳答案by Derek Hunziker

What you have here should work with the Droplink field. Perhaps you are referring to Droptree?

您在此处拥有的内容应该适用于 Droplink 字段。也许您指的是 Droptree?

query:./ancestor::*[@@templatename='CountryHome']/METADATA/Regions/*

As for the TreelistEx, I don't think the default Treelist fields support Sitecore query. However, this articledescribes how to create a custom TreeList that supports it.

至于 TreelistEx,我认为默认的 Treelist 字段不支持 Sitecore 查询。但是,本文介绍了如何创建支持它的自定义 TreeList。

回答by Stephen Pope

Fields that support Sitecore Query

支持 Sitecore 查询的字段

Where you can use the syntax query:or fast:(for FastQuery):

您可以在哪里使用语法query:fast:(对于 FastQuery):

  • Droplist
  • Grouped Droplist
  • DropLink
  • Grouped Droplink
  • Checklist
  • Multilist
  • Droptree
  • 下拉列表
  • 分组下拉列表
  • DropLink
  • 分组下拉链接
  • 清单
  • 多列表
  • 滴树

Fields that support Parameterized Datasource

支持参数化数据源的字段

Where you can use enhanced syntax with Parameterized datasource query:

您可以在哪些情况下将增强语法与参数化数据源查询结合使用:

  • Droptree †
  • Treelist
  • TreelistEx
  • 树 †
  • 树列表
  • TreelistEx

Droptree only supports the Datasourceand DatabaseNameparameters.

Droptree 仅支持DatasourceDatabaseName参数。

The enhanced query string syntax includes the following parameters:

增强的查询字符串语法包括以下参数:

  • Datasource
  • DatabaseName
  • AllowMultipleSelection
  • IncludeItemsForDisplay
  • ExcludeItemsForDisplay
  • IncludeTemplatesForSelection
  • ExcludeTemplatesForSelection
  • IncludeTemplatesForDisplay
  • ExcludeTemplatesForDisplay
  • 数据源
  • 数据库名称
  • 允许多选
  • IncludeItemsForDisplay
  • 排除显示项
  • 包括选择模板
  • 排除模板选择
  • IncludeTemplatesForDisplay
  • 排除显示模板

These are used like this: Datasource=/sitecore/content/home/Products/&IncludeTemplatesForDisplay=Product Category&ExcludeTemplatesForSelection=Product Description&IncludeTemplatesForSelection=Product Category

这些是这样使用的: Datasource=/sitecore/content/home/Products/&IncludeTemplatesForDisplay=Product Category&ExcludeTemplatesForSelection=Product Description&IncludeTemplatesForSelection=Product Category

Mark Ursino has a great post on how to use this kind of syntax here.

Mark Ursino 在此处发表了一篇关于如何使用这种语法的精彩文章。