Page Editor Experience – Set the Datasource Template for the Presentation Component

Dear Sitecore Family,

Yesterday, we saw how selecting a Datasource Location helps the Business User.

Today, lets take it a little further, lets see if we can do something so that the Business User is not confused between selecting the type of Datasource Item for a component, if there are a number of components available at the specified Datasource Location.


Can we make the Business User journey easier while working with Sitecore by specifying the Type of Item that is expected as a Datasource Item by the Presentation Component?


Again, the answer is Yes! Thank you Sitecore!

Oh, you want to know how can this be done?

Well, lets check that out.

Quoting an example from the Launch Sitecore 8 Demo Site and again considering the Carousel Component. In every Presentation Component – whether a Rendering or a Sublayout, there is an item field called Datasource Template. [Note: Sitecore as already provided the value for this field in Launch Sitecore site, I have removed it for our understanding purpose, of how things work when this field value is not specified at first and then specified later.]

We will make use of this field, to specify the Type of Datasource expected by the component.


By default, for any Presentation Component, this field is empty. So, whenever the Business User tries to set the Datasource from Page Editor, this is what he/she will see.



See that, the Business User can select any item as a Datasource.

Now, lets check what happens when we set the Datasource Template, for the Rendering.



And now checking the Select Associated Content dialog from Page Editor.



Oh Wow!

So this is what happens. Sitecore Validates the item that is selected as a Datasource and if the Datasource Item is not of the Template specified above, it cannot be added as a Datasource.

At the same time, Sitecore gives us a nice validation message for the understanding purpose.

Simple and Useful right?

Hope you enjoyed the post!

Happy Sitecoring! :)

Page Editor Experience – Select the Datasource Location in a Presentation Component

Dear Sitecore Family,

How you been? Hope you are enjoying these posts on Sitecore Page Editor a.k.a Sitecore Experience Editor?

Today, lets discuss about making the Business User journey smoother with Sitecore, while working with their own Website.


When the properties Dialog opens and the Business User clicks on the Datasource, he/she is kind of lost in the Sitecore Content Tree. Can there be a way to get to the specific content?


Well, the answer is yes, as it is Sitecore!

How do we get it done?

Lets take an example of Launch Sitecore Site to understand the scenario. Currently considering the Carousel Rendering. In every presentation component, we have a field called Datasource Location

By default, its empty. So whenever we go to the Page Editor and try adding the Datasource, we get the Content Tree starting with Content.


Now, lets add a Datasource Location and see what happens.

As Sitecore has done, lets add the following Location as a Datasource:


of the field Datasource Location in Carousel


Now, whenever we go to the Page Editor and open the Properties Window or Set Associated content for the Carousel Component, it directly opens as follows:

When-Datasource-is-assignedVery useful right? Our Business Users don’t need to go and search for the Datasource in the whole content tree.

Hope you found the post useful!

Happy Sitecoring! :)

Page Editor Experience – Select Associated Content after adding a Presentation Component on Page

Dear Sitecore Family,

A very small yet useful post today.

Sometime back, we saw how to add a Component with a DataSource. In case you missed it, here’s how we do it.

When we add a presentation Component from Page Editor which requires a Datasource, we need to go and Set associated content for it.


Now, for a Business user, its difficult to know that he or she needs to select a Datasource, in case we have some good documentation for it, then its ok. So it becomes the responsibility of the developer, to make things easy for the Business User.


How do we  make things easy for the Page Editor User/Business User?


While creating the Sublayout, we are provided with an option as shown below:

Open-Properties-after-AddBy default, the value is “Default” which means No — Let’s make it Yes from the DropDown


After this, whenever the Business User tries to add that particular component onto the page, he/she will find the checkbox to be disabled.


And, on adding it on the page, the Properties Dialog will open immediately,


which in a way, notifies the Business User that some action needs to be taken — Add a Datasource.


Hope you liked the post!

Happy Sitecoring! :)

Setup Visual Studio Project with Post Build Script

Dear Sitecore Family,

This post is in continuation to the post Setup Sitecore Developer Box in less than 5 minutes.

Here, we will discuss another way of Setting up the Visual Studio project in such a way that we do not need to use Visual Studio Publish .


A Developer needs to Publish the Changes everytime he/she wants to sync it with the Sitecore Website. For some, this can be a useful point – say someone who builds the visual studio solution on a regular basis just to check that things are doing fine till that time, but doesn’t want the Sitecore Website to restart everytime, this would be an ideal scenario. At some point of time, even I do it that way, I just build to check hope there is no build error or warning till that point of time, but as there are some more things left to code, I don’t want to merge them to my Sitecore Website and unnecessary restart it.

But in case when I want to sync the changes to the Sitecore Website, I need to go and say “Publish” to my Visual Studio solution — indeed a step more, which we can save.

On discussing this with Mr. Brijesh PatelTech-It Pro Author, he told me, why do I require do an additional step everytime? And then even I felt what he said, had an important point!


He asked me Varun, remember some Build related events? Yes, it is the Post-Build Event which is of our concern!

Then, we went and configured the Post Build Event in a project and it worked like charm! Here’s how we did it.


  1. After Step 2 of the Previous Post, go to the Directory Structure of the Visual Studio Solution and open the main Web Project File (.csproj) — in Notepad or Notepad++.
  2. Go to the End of File, and we will see a commented section – after ProjectExtensions.
     <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
    Other similar extension points exist, see Microsoft.Common.targets.
    <Target Name="BeforeBuild">
    <Target Name="AfterBuild">
  3. Uncomment the Target with name “AfterBuild” and add a few lines of configuration to it. Basically, we will add a few lines into the ItemGroup Section inside AfterBuild, and then we will add the Copy Tag to specify where should the specified files be copied! Here’s how we would do it.
      <Target Name="AfterBuild">
    <MyBinDllFiles Include="$(ProjectDir)\bin\**\*.*" />
    <MyConfigFiles Include="$(ProjectDir)\App_Config\Include\**\*.config" />
    <MyImageFiles Include="$(ProjectDir)\VisualStudioSampleProject\StaticResources\Images\**\*.*" />
    <MyFontFiles Include="$(ProjectDir)\VisualStudioSampleProject\StaticResources\Fonts\**\*.*" />
    <MyStyleFiles Include="$(ProjectDir)\VisualStudioSampleProject\StaticResources\Styles\**\*.css" />
    <MyScriptsFiles Include="$(ProjectDir)\VisualStudioSampleProject\StaticResources\Scripts\**\*.*" />
    <MyLayoutFiles Include="$(ProjectDir)\VisualStudioSampleProject\Layouts\**\*.aspx" />
    <MySubLayoutFiles Include="$(ProjectDir)\VisualStudioSampleProject\Sublayouts\**\*.ascx" />
    <Copy SourceFiles="@(MyBinDllFiles)" DestinationFiles="@(MyBinDllFiles->'C:\Websites\Sitecore\SitecoreSolution\Website\bin\%(Filename)%(Extension)')">
    <Copy SourceFiles="@(MyConfigFiles)" DestinationFiles="@(MyConfigFiles->'C:\Websites\Sitecore\SitecoreSolution\Website\App_Config\Include\%(RecursiveDir)%(Filename)%(Extension)')">
    <Copy SourceFiles="@(MyImageFiles)" DestinationFiles="@(MyImageFiles->'C:\Websites\Sitecore\SitecoreSolution\Website\VisualStudioSampleProject\StaticResources\Images\%(RecursiveDir)%(Filename)%(Extension)') ">
    <Copy SourceFiles="@(MyFontFiles)" DestinationFiles="@(MyFontFiles->'C:\Websites\Sitecore\SitecoreSolution\Website\VisualStudioSampleProject\StaticResources\Fonts\%(RecursiveDir)%(Filename)%(Extension)')">
    <Copy SourceFiles="@(MyStyleFiles)" DestinationFiles="@(MyStyleFiles->'C:\Websites\Sitecore\SitecoreSolution\Website\VisualStudioSampleProject\StaticResources\Styles\%(RecursiveDir)%(Filename)%(Extension)')">
    <Copy SourceFiles="@(MyScriptsFiles)" DestinationFiles="@(MyScriptsFiles->'C:\Websites\Sitecore\SitecoreSolution\Website\VisualStudioSampleProject\StaticResources\Scripts\%(RecursiveDir)%(Filename)%(Extension)')">
    <Copy SourceFiles="@(MyLayoutFiles)" DestinationFiles="@(MyLayoutFiles->'C:\Websites\Sitecore\SitecoreSolution\Website\VisualStudioSampleProject\Layouts\%(RecursiveDir)%(Filename)%(Extension)')">
    <Copy SourceFiles="@(MySubLayoutFiles)" DestinationFiles="@(MySubLayoutFiles->'C:\Websites\Sitecore\SitecoreSolution\Website\VisualStudioSampleProject\Sublayouts\%(RecursiveDir)%(Filename)%(Extension)')">
  4. Go to Visual Studio with the Project open – it will ask to Reload the Web Project as it has undergone some changes, say yes and we are done!
  5. Make some changes and say Build Solution – and our changes are visible in the Sitecore Website!


In a Developer Box, it is always useful to configure the Post-Build Event rather than using the Visual Studio Publish for merging changes with the Sitecore Website, as suggested in Step 3 of the previous post! This is to avoid performing an additional step everytime we need to sync the changes! And as far as saving code changes on a regular basis, we can anytime use Ctrl+Shift+S — to save all the changed files.

The Step 3 – of Visual Studio publish is good when we want to deploy the Project changes to Sitecore Website on different environments, say we are merging the changes from our Local Box to the Internal Integration Testing Environment or the UAT Server.

Hope you enjoyed the post!

Happy Sitecoring! :)

Page Editor Experience – Fetch the Datasource in code of a Presentation Component

Dear Sitecore Family,

In the previous 2 posts, we just saw how to configure a Datasource in a  Presentation Component and Adding a Component from Page Editor.

The previous posts are not of any specific use, if we don’t see how do we retrieve it in code and how do we display it!

So lets just have a look at it.

Well the first thing, as we all know, its always good to use the DRY Rule of Software Engineering!

Step-1: So instead of writing a big piece of code to fetch the Datasource, its good to use the Sitecore Module Sublayout Parameter Helper by John West.

Step-2: We change the inheritance of the Sublayout Component – we change it from System.Web.UI.UserControl to Sublayoutbase as follows:


public partial class SublayoutDatasourceSample : System.Web.UI.UserControl


public partial class SublayoutDatasourceSample : SublayoutBase

Step-3: After the above step, when we build our solution and check for DataSourceItem in our Sublayout Page_Load function code, its available — this is a property visible from the SublayoutBase class!


So we just apply a couple of required validations and next is assign it as the Item for the various fields we have created.

Say, I add a couple of FieldRenderers in the ascx code,

<sc:FieldRenderer runat="server" ID="Header" FieldName="Heading" />

<sc:FieldRenderer runat="server" ID="Content" FieldName="Content" />

And using the DataSourceItem property, I assign the Item to these two controls as follows:

public partial class SublayoutDatasourceSample : SublayoutBase
protected void Page_Load(object sender, EventArgs e)
Header.Item = DataSourceItem;
Content.Item = DataSourceItem;

And the work is done!

So we see, how easy it gets when we are aware of the things that are already available and how to use them.

Thank you John West for this Awesome Module, it definitely saves us from a lot of repetition of code in various Sitecore Projects!

Happy Sitecoring!

Page Editor Experience – Add a Datasource in a Presentation Component

Dear Sitecore Family,

The previous post, was about Configuring a Datasource in a Presentation Component and my friend Nikki Punjabi suggested that it doesn’t feel complete without showing the steps to add a datasource to a component. In a way, I agreed to his point, that the post seemed incomplete.

So this post is about the steps to add a Datasource in a Presentation Component – in our case a Sublayout. And as we are talking about Page Editor Experience, I’ll present the steps for adding via Page Editor.


  1. Login to Sitecore and open the Page Editor.
  2. Next, from the Page Editor Ribbon Click on the button Add a New Component.Page-Editor-Add-Component
  3. If the above shown button is disabled then it either means you don’t have rights or the Designing Checkbox is unchecked. Hence, go to the View Tab on the Ribbon and check the Designing Checkbox. Next, On clicking that button, We get the option of adding a new Component as below.Add-Component-Option-Add-To-Here
  4. These “Add to here” buttons show the location where we can add components, in the specific placeholders – in our case – sidebar and content. Click this button and we get an option of selecting a rendering. Select the Featured Posts component, check the checkbox “Open the Properties dialog box immediately.” and click select.Add-Component-Select-Rendering
  5. And the component is added. Now, the Properties dialog will open. Add-Placeholder-Open-Properties-Window
  6. Next, click on Browse, and Select the Datasource from the Select the Associated Content Dialog. Add-Component-Select-Associated-Content
  7. Now, Click Ok and the Item ID of your Datasource Item will appear in the Properties Window Datasource Field. Add-Component-DataSource-Selected
  8. Click on Ok and the component is rendered on the Page as below.DataSource-Appears-on-Page-Editor

Hope this post was helpful and that it now completes the previous one!

Happy Sitecoring!

Page Editor Experience – Configure a Datasource in a Presentation Component

Dear Sitecore Family,

Hope you are doing good? Sorry for being away from my blog for a long time, been busy with some personal responsibilities. As it was weekend, so thought why not write a post today!

In the previous post on Page Editor Experience, we saw how adding a thumbnail image to a presentation component, gives a better Page Editor Experience to our Page Editor users. In case you missed it, have a look at it here Page Editor Experience – Add a Thumbail Image to our Presentation Component

Here, lets have a look at how useful it can be configuring and assigning a Datasource to our Presentation Component.

Sitecore is a very flexible Web Content Management system, and we can architecture a site as per our requirement. There is no wrong or right way to do it. But, to take advantage of the real power of Sitecore, in all our projects, while we are designing the architecture itself, we should design our pages to contain distinct and decoupled presentation components.

For this matter, the current content tree structure that I have chosen is as below.


Although, I completely agree to a point, that there can be an even better structure and we should design it based on our requirements.

Lets consider some basic questions — What, Why and How? — and we would understand the above point of its usefulness.

So, What is a Datasource in context to a presentation component?

While developing an ASP.NET website, we have used various data controls like Repeater and Gridview, in the backend code we query the required data and present the available Dataset to these data controls as DataSource. This is the concept of a Datasource in ASP.NET website. In a similar way, when we are considering a Datasource in Sitecore, its about an item in our content tree. We design various page sections in a reusable way, and assign them to an item’s Sublayout or Rendering component, in its Presentation Details with the some other content item acting as the data item for the component. (If this was confusing, lets see an example to know more!)

Why use Datasource in a Presentation Component?

It has three main advantages:

  • Reusability of the Presentation Components: We do not need to either duplicate the presentation component or the structure of the items, but just configure the source as per our requirement. Also, we can use the same Presentation component for multiple sites, if the need be, by simply changing its datasource as per the requirement!
  • Empowering Client Users: Content Authors and Page Editor users can work separately. Content Authors don’t have to visit multiple items to change the content to update similar content on various pages.  Page Editor users might select an item for a page as per the new requirement and the data is readily available on the page.
  • Better Testability and Ease of use: Our users don’t need to go and check each and every page where a specific content needs to be changed. That specific content, is available at a single location as the datasource of our presentation component. So, changing that content, the change is directly reflected at all those locations.

How to Configure a Datasource for our Presentation Component?

In previous posts, we have considered a case of a Blog website and to make things simple lets consider the same here.

We will consider 2 cases:

Presentation Component: Featured Post Sublayout

Locations: Homepage Footer, Blog Landing page Left Sidebar & Blog Detail Page Left Sidebar

  • Use of datasource for a presentation component in a single site

Once the Featured Post is configured on all the 3 locations, whenever the client users (say Content Authors) want to change the Featured Posts,  they need not go and change in each and every page specific content. They can change the item selected in the Datsource item, and that gets reflected on all the sections mentioned above.

Considering an example, say previously, we had configured 2 of our blog items for Featured Posts as follows:

Now, we thought of adding one more post to the list of featured posts. So this is how we do it:

And the change is reflected at every location where this item is selected as a datasource. In this way, we can have a better testability as well as ease of use for our client users, making their life easy.

  • Use of datasource for a presentation component in multiple sites

In case of multiple sites, each of them having blogs, the Datasource item would be different (i.e. site-specific) while having the same Presentation Component (i.e. Featured Post Sublayout). Thus, for each site, we might create the Featured post item as in the above screenshots, and set them as Datasource for the Featured Post Sublayout Component. Thus, we can reuse the same component on multiple sites too.

Hope you liked the post!

Happy Sitecoring! :)