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! 🙂