Datasource with Multisite – Sitecore Queries

This article is really small but covers good thing which we (The developers) may not considered to while implementing solution. Its about restrict the selection to the Editor or Author.

Answer is Sitecore Query. There are many articles around this i have added some good articles of links in this blog but yes, lets have some examples to configure simple selections:

Scenario 1: Consider we need to give option to Author to select Countries which are common or restricted to the site. Consider its Multisite as well. below is an example.
l1

Here below is the datasource:

query:./ancestor::*[@@templatename='WebsiteFolder']/Settings//*[@@templatename='Countries']/*

Which says retrieve children of Item created from “Countries” template that is a Home node, a child of Item created from the template “WebsiteFolder“.

Below is the screen about content tree where there are 2 sites (Site1 and Site2) and both have different countries. by writing above query in datasource

l4

And the result is for Site1:

l2

And for Site2:

l3

Scenario 2: Normally we use to have an option to select may be a search page or contact us page of the existing site, example Site1. Below could be a datasource to select page inside the Site1 only.
2017-05-22 06_27_57-Desktop
FieldType is: Treelist

Datasource:
query:./ancestor::*[@@templatename='WebsiteFolder']/Home

Which will list items in the Treelist starts from Home of the Site1.
2017-05-22 06_31_15-Desktop
References:

Click to access using%20sitecore%20fast%20query001.pdf

https://community.sitecore.net/technical_blogs/b/sitecorejohn_blog/posts/sitecore-query-cheat-sheet

I will add more references in this article about sitecore queries.

Happy Coding….

Note: Sitecore queries may decrease performance of your application so be careful while using Sitecore queries

2 thoughts on “Datasource with Multisite – Sitecore Queries

Add yours

  1. The use of “//” or the descendant axis in Sitecore is highly discouraged and should be avoided in all cases. Please do not use this approach.

    1. Any references from sitecore about not using such? as they are suggesting such with a note that Sitecore query will slow the performance of the site.

      It will be a good for all if have any reference.

Leave a comment

Create a website or blog at WordPress.com

Up ↑