Query notation for the sitecore 'source' field in template builder
Asked Answered
K

2

14

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.

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:

 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

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.

Help!

Kaduna answered 26/9, 2012 at 22:13 Comment(0)
C
14

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

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

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

Cauda answered 26/9, 2012 at 23:1 Comment(2)
ahh yes, I have a droptree, not droplink. That sucks though - the manuals all say that any fields with 'source' field should work. So this doesn't work on droptree?Kaduna
I found the different fields support different variations of the query syntax. It seems they have been developed completely independently. Best is to submit a ticket with sitecore.Adjustment
M
46

Fields that support Sitecore Query

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

  • Droplist
  • Grouped Droplist
  • DropLink
  • Grouped Droplink
  • Checklist
  • Multilist
  • Droptree

Fields that support Parameterized Datasource

Where you can use enhanced syntax with Parameterized datasource query:

  • Droptree †
  • Treelist
  • TreelistEx

Droptree only supports the Datasource and DatabaseName parameters.

The enhanced query string syntax includes the following parameters:

  • Datasource
  • DatabaseName
  • AllowMultipleSelection
  • IncludeItemsForDisplay
  • ExcludeItemsForDisplay
  • IncludeTemplatesForSelection
  • ExcludeTemplatesForSelection
  • IncludeTemplatesForDisplay
  • ExcludeTemplatesForDisplay

These are used like this: 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.

Marrilee answered 27/9, 2012 at 9:14 Comment(5)
Thanks for the response! In the end, I made the custom field that supports xpath, and used that. But this is definitely useful for simpler queries..Kaduna
BTW - that blog you posted the link to is Mark Ursino's blog :) Brian Pederson's blog is very informative as well..Kaduna
The exclude parameters don't seem to work on Droptree but they do in Treelist. Ugh!Rochus
SDN says only TreeList and TreeListEx support parameterized data source. Making Droptree officially totally useless.Rochus
As of SC 6.6 Droptree accepts a SC query with the query: format. Just confirmed in a project I'm working on.Caerleon
C
14

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

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

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

Cauda answered 26/9, 2012 at 23:1 Comment(2)
ahh yes, I have a droptree, not droplink. That sucks though - the manuals all say that any fields with 'source' field should work. So this doesn't work on droptree?Kaduna
I found the different fields support different variations of the query syntax. It seems they have been developed completely independently. Best is to submit a ticket with sitecore.Adjustment

© 2022 - 2024 — McMap. All rights reserved.