Offcourse we all know that there is a way to set queryable datasources to sublayout definitions in the Sitecore database to help us select appropriate data for our renderings. This can be done using a module that you can find on the marketplace:
This module – when you specify a sitecore query – changes the rendering datasource to a new location. This can be very handy when you work with the page editor and want content of specific items to be placed underneath the content item itself. You can then for example place a “/content” folder underneath your items to hold the specific content that will be displayed on your item.
What I’ve noticed during development of a new Sitecore website that uses the page editor is that it can be very handy to have a complete page setup for our content editors so they see how a page should look. Giving the editors the ability to change existing layout is generally more appreciated than giving them a blank page that they have to fill from scratch everytime they add a new page / content item.
To achieve this goal we create a new “branch” for this set of items that will help our editors to quickly fill a new content item. This branch could for example have the following structure:
What you see here is a branch on which we have filled specific content items and other data template based items that will be used in our branch. When the content editor creates a new item from this branch, we wanted the presentation details of this branch to have those items preselected without having them central /in a shared folder somewhere in Sitecore. Every branch would then create this structure and the item created would have it’s own items underneath that would be used in the presentation. This offcourse could be done with the same concept as we’ve seen before in the Queryable Datasource. We went to see how Sitecore actually determines what item to present in a sublayout and found out we could play a little with the “ProcessContextQuerySource” pipeline.
We did the following: (after decompiling the Sitecore.Kernel.dll)
- Create a new processor definition in the config that replaces the ‘Sitecore.Pipelines.InsertRenderings.Processors.AddRenderings, Sitecore.Kernel’ pipeline.
<processor type="YOURNAMESPACE.Framework.Pipelines.InsertRenderings.AddRenderingsQueryable, YOURDLL.Framework" />
<processor type="Sitecore.Pipelines.InsertRenderings.Processors.AddRenderings, Sitecore.Kernel">
- Create a class that inherits “Sitecore.Pipelines.InsertRenderings.Processors.AddRenderings” and implement it using the following code:
public class AddrenderingsQueryable : Sitecore.Pipelines.InsertRenderings.Processors.AddRenderings
public override void Process(Sitecore.Pipelines.InsertRenderings.InsertRenderingsArgs args)
if (args.ContextItem == null)
DeviceItem device = Sitecore.Context.Device;
if (device == null)
RenderingReference renderingReferences = args.ContextItem.Visualization.GetRenderings(device, true);
RenderingReference queryableDatasources = renderingReferences.Where(c => c.Settings.DataSource.Contains("query:")).ToArray();
renderingReferences = renderingReferences.Where(c => !c.Settings.DataSource.Contains("query:")).ToArray();
foreach (RenderingReference thisQueryableDatasource in queryableDatasources)
Item datasourceItem = Sitecore.Context.Item.Axes.SelectSingleItem(thisQueryableDatasource.Settings.DataSource.Replace("query:", string.Empty));
if (datasourceItem != null)
thisQueryableDatasource.Settings.DataSource = datasourceItem.Paths.FullPath;
args.HasRenderings = args.Renderings.Count > 0;
Now when sitecore is adding renderings to the page and finds a rendering that has a query: in the datasource it will be picked up as a special rendering. This class will extract all renderings with “query:” in it’s datasource and sets the appropriate datasource for those renderings. Pretty neat huh?
You can now add a sublayout on your branch item with the following query to set default text:
When the item is created from the branch it will initially point to the item underneath itself, but the content editor is free to change to another datasource if needed. When you click the ‘set associated content’ button the usual stuff will happen, making sure that you can set different content as datasource.
I do realise that this concept is taken from the queryable datasource, tho I think that this might be useful to setup a branch with item specific data underneath the content item itself (without having to create shared content items somewhere to point at from the datasource).
That’s it for now!