I have a page template where when the site was setup it referenced the folder(Item ID), but now I have multiple sites and need it to reference ONLY the sites folders not just the main site. I am trying to run a query that will just select this folder from the selected site. So I have site Red and a site blue and a site green, under the sites I have the corresponding datasources and that is what I need to call in with this query. So site red needs to point to its corresponding red datasource with the countries folder under it, SAMPLE is the second image, trying to point to that countries folder.
2 Answers
What you need to do is walk back up the tree to your Site root item and then path down to the Datasource folder you need. You can do it something like this:
query:./ancestor-or-self::*[@@templatename='Your SiteRoot Template']/#red datasource#/Countries
This is saying ./
start at the current item, ancestor-or-self
- get the first item either me or any of my parent (ancestor) items that match the template name of your site root template, /#red datasource/countries/*
give me all the items at this path.
-
I forgot to mention this is for a multilist datasource, could this be possible to grab the ID for it since that is how it was setup before. Commented Dec 31, 2021 at 17:11
So this is what I ended up coming up with, with the help of the above response.
query:./ancestor-or-self::*[@@templateid='{AD55B888-20A7-43A3-B487-6FE5658F9DAC}']//*[@@templatename='Country']
So Richard thanks for helping me in the right direction.
-
2You should accept the answer that actually solved your problem, not just repost the answer and self-tick it.– Mark Cassidy ♦Commented Jan 7, 2022 at 6:00
-
Your use of
//*
descendents query is likely to lead to performance issues too. You should follow the pattern that Richard had provided in the example and specify as much of the interim folder structure as possible.– jammykamCommented Jan 7, 2022 at 15:28