1

I have an Example page with a control on it. I want to reference a grandchild SubItem in that control.

Example > Page Data > SubItem

When I specify the full path as the Data Source everything works fine. However, I want to specify a relative path and can't get it to work. The control can't seem to find the SubItem. I'm trying to do a query and I think my syntax may just be wrong.

Data Source: query:./Page Data/SubItem

Any help would be appreciated. I'm using Sitecore 9.0. Thanks!

3
  • Are you planning to set the datasource with the same name "SubItem" for all the pages? In case if you are planning to set it at the rendering definition, setting it via template id makes more sense and let the content author choose the item they want. query:./*[@@templateid='{5DF4FC1C-053E-43EC-BEC4-1675825ABE3A}'] Commented Jan 18, 2022 at 22:29
  • Doesn't appear to work. Query Builder accepts this, but doesn't provide a clear way to specify grandchildren under the Page Data folder only: template:{38585AEF-9722-433B-8279-F9BDD7951A0C}
    – Justin
    Commented Jan 19, 2022 at 0:21
  • github.com/Gatogordo/LocalDatasources
    – Mark Cassidy
    Commented Jan 20, 2022 at 23:21

3 Answers 3

1
+50

If I understand correctly you are trying to work with "local datasources". This is something well known in SXA, but if you are not using that in your project it can be a bit tricky. A few years ago I created a module to help you with that. I can not guarantee that everything will work in your Sitecore version as the module is already a few years old (build for 8.2) but it's open source so you contribute or just use the code as a starting point for your needs.

The blog post about the local datasources module will give some more insights. The code can be found on GitHub: https://github.com/Gatogordo/LocalDatasources where you can also check the readme page on how to use it.

The solution consists of several parts:

  • The first part will create the actual datasource item (and the data folder if that does not yet exists - datafolder will be pushed as latest child). The template name of the required datasource is used as base for the item name, combined with a number. This is all configurable on the rendering based on the settings of the datasource template and location.
  • A second part will prevent the "Select the associated content" dialog from appearing.
  • Some support for working with branches was also added

This is not an ootb solution but if you don't have SXA included in the project it can help you achieve what you are looking for.

1

At a quick glance, I think the issue might be as simple as the fact that your item heirarchy contains items with spaces in the names.. Have you tried escaping the space?

Try setting your query to:

query:./#Page Data#/SubItem

A similar question and answer can be found here.

set relative query to datasource

0

Couple of ways to achieve this:

  1. You can use the Build Query option to build a query like this:
template:{C89F3FC7-C67E-4CC0-B3E4-3AA25D50230D};+custom:_path|{70252CF8-066C-45C0-A367-B34D8A080543}

Where template is the template id of grandchildren items (template id of SubItem in your case) and _path is the ID of parent/ancestor (Item ID of Example in your case).

enter image description here

  1. You can create your own query and direcly paste in Query field. For your case, query should look like:
query:$home//*[@@name='Example']//*[@@templatename='SubItemTemplateName']

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.