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:

https://sdn.sitecore.net/upload/sdn5/developer/using%20sitecore%20fast%20query/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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: