1

The content tree is like this

sitecore
|_ content
  |_ Home
    |_ Datasources
      |_ Banners
  |_ About
    |_ Datasources
      |_ Banners
  |_ Datasources
      |_ Banners

Home & About are pages.
All Datasources are folders of the Datasources Folder template.
All Banners are folders of the Banners Folder template.

I would like to set the datasource location for the Banner rendering, which should work as follows.

For Home page, when user clicks on Browse to choose a Banner datasource, then only these locations should be displayed.

sitecore
    |_ content
      |_ Home
        |_ Datasources
          |_ Banners
      |_ Datasources
          |_ Banners

And for About page, when user clicks Browse to choose a Banner datasource, only these locations should be displayed.

sitecore
    |_ content
      |_ About
        |_ Datasources
          |_ Banners
      |_ Datasources
          |_ Banners

Meaning, only the 'global' Banners folder and the respective page's Banners folder should be displayed.

Is it possible. If yes, could you please share the query.

1

1 Answer 1

3

You can use Sitecore queries to do this in the same way that SXA does, albeit with slightly more complex queries as you don't have the SXA tokens to use. Here is something to start you off:

query:./*[@@name='Datasources']/*[@@templatename='Banners Folder Template']|query:./ancestor-or-self::*[@@templatename='Your Site Root Template']/*[@@name='Datasources']/*[@@templatename='Banners Folder Template']

Note the | separating the 2 queries, you can add more if you need too. That would give you the 2 matching folders for your datasource as long as those folders exist.

You would add this to the Datasource Location field on the rendering item.

5
  • Should this query be added in the Datasource Location field of a rendering. I did that and when I try to pick a datasource, it says ""::" expected at position 18.". Also, what is _Datasources and should we not specify the 'Datasources Folder' template just like 'Banners Folder', anywhere?
    – sukesh
    Jun 7, 2022 at 14:12
  • Update the answer to indicate the field. If you look at the query, it is querying by name for the _Datasources folder, I used that as in your example, that's what you called it. You can change that to a template query if you want. It's up to you.
    – Richard Seal
    Jun 7, 2022 at 14:35
  • You could also just use a path like query:./_Datasources/ instead of a filter there.
    – Richard Seal
    Jun 7, 2022 at 14:36
  • It's still the same error and here is my query. query:./*[@@name='Datasources']/*[@@templatename='Banners Folder']|query:./ancestor-or-self[@@templatename='Sample Item']/*[@@name='Datasources']/*[@@templatename='Banners Folder']
    – sukesh
    Jun 7, 2022 at 14:57
  • 1
    make ancestor-or-self into ancestor-or-self::*
    – Richard Seal
    Jun 7, 2022 at 16:01

Your Answer

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

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