sitecore Sitecore query syntax Site-specific query


Example

Tree structure:

/sitecore
    /content
        /foo-site
            /home
                /my-account
        /bar-site
            /home
                /my-account
        /baz-site
            /home
                /my-account
  • The template of each site item (foo-site, bar-site, baz-site) is named Site Node.
  • The template of each home item (home, home, home) is named Homepage
  • The template of each user account item (my-account, my-account, my-account) is named User Account Page

Current Item:

The current item could be the home item or any page underneath the home item for any of the given sites, and this query will still work (provided that there are no items with the Homepage template underneath the home items that are an ancestor of the current item).

Query:

query:./ancestor-or-self::*[@@templatename='Homepage']/*[@@templatename='my-account']

Result:

If querying from the home item or one of its descendants in the foo-site site:

/sitecore/content/foo-site/home/my-account

If querying from the home item or one of its descendants in the bar-site site:

/sitecore/content/bar-site/home/my-account

If querying from the home item or one of its descendants in the baz-site site:

/sitecore/content/baz-site/home/my-account