In Sitecore, one can easily get the list of all the datasources that are linked to renderings on the page. Why do we need this? During development, business logic may require to look for a value in all the datasources that are linked to a page. I have seen people writing methods as below, but this can be done way more easily in one line - private List<Item> GetRenderingDataSourceItems(Item item) { var items = new List<Item>(); var renderings = item.Visualization.GetRenderings(Sitecore.Context.Device, true); foreach (var rendering in renderings) { //This check ensures only items are added, not queries if (Sitecore.Data.ID.IsID(rendering.Settings.DataSource)) { var dsItem = item.Database.SelectSingleItem(rendering.Settings.DataSource); if (dsItem != null) { //Add the datasource item
This blog is created to serve as a repository of quick tips for Sitecore developers. I have learnt a lot from the programming community and this is my attempt to give back to the community.