I want to access the layout description of an element so that I can access the visualization added to the element and then access the data sources attached to the specified visualization. I can't seem to find a way to do this. The best I could do was access the field __renderings, but then it turned out that it would be access to the original element of the rendering definition, and not to a specific instance with the data stored in the design layout.
This is on Sitecore 7.5 MVC
If this helps, this is what I tried to do:
DeviceRecords devices = item.Database.Resources.Devices;
DeviceItem defaultDevice = devices.GetAll().Where(d => d.Name.ToLower() == "default").First();
Sitecore.Data.Fields.LayoutField layoutField = item.Fields["__renderings"];
Sitecore.Layouts.RenderingReference[] renderings = layoutField.GetReferences(defaultDevice);
RenderingItem headerRenderingItem = null;
RenderingItem aboutRenderingItem = null;
foreach (var rendering in renderings)
{
if (rendering.Placeholder == "headerPlaceholder")
headerRenderingItem = rendering.RenderingItem;
else if (rendering.Placeholder == "/aboutSectionPlaceholder/textPlaceholder")
aboutRenderingItem = rendering.RenderingItem;
}
Assert.IsNotNull(headerRenderingItem, "no header rendering item found");
Assert.IsNotNull(aboutRenderingItem, "no about rendering item found");
ID headerDatasourceId = ID.Parse(headerRenderingItem.DataSource);
ID aboutDatasourceId = ID.Parse(aboutRenderingItem.DataSource);
source
share