Skip to content
June 4, 2012 / kiranpatils

Basics of reading layout delta programmatically

Challenge:

Before few weeks, we upgrade our solution to Sitecore 6.4.1, which looks really great (Would you like to know what’s new in Sitecore 6.4? Read my earlier blog post), and supports layout delta feature. Which looks promising! (If you are new to layout delta, then please read Layout Delta articles given in Good to read section at bottom of this post)

Now, Something new comes with new challenges, and so as Layout Deltas. Before SC 6.4 we were having few functionality where we were reading Layout Renderings. But after SC 6.4 that has changed (Earlier it was storing full rendering data in item’s template under standard values __ Rendering field. But after SC 6.4 users can modify Item’s rendering details. And if user does so Item will store it’s changed values — Layout Delta only in its __ Rendering field)  Now, if you are also facing the same challenge. i.e. Wanted to read id and placeholder of all the renderings (Not only Layout Delta) and controls used in an item then this post is for you!

Solution:

We tried a lot from our side. But haven’t found any solution. Then we contacted our Sitecore experts which is Sitecore support team and as always they have given best solution to us! (So, if following solution helped you, please say thanks to Sitecore support champs!)

Following approach is useful to get full(not layout deltas) value from the item  “__Renderings” field  and shows how you can find all renderings for item presentation.


Sitecore.Data.ID id = Sitecore.Data.ID.Parse("E0CE372F-7755-4DED-A1A7-5DD4D9B0B43A"); // Replace by your Item's ID
Sitecore.Data.Items.Item item = Sitecore.Data.Database.GetDatabase("master").GetItem(id);
string l = Sitecore.Data.Fields.LayoutField.GetFieldValue(item.Fields["__Renderings"]);
LayoutDefinition layout = LayoutDefinition.Parse(l);

foreach (DeviceDefinition dev in layout.Devices)
{
if (dev != null)
{
var renderings = dev.Renderings;
if (renderings != null)
{
foreach (RenderingDefinition rend in renderings)
{
Response.Write(rend.Placeholder.ToString());
Response.Write(rend.ItemID);
Response.Write("</br>");
}
}
}
}

Good to read:

http://www.sitecore.net/community/technical-blogs/getting-to-know-sitecore/posts/2010/10/layout-deltas-what-ifs.aspx

http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2011/09/Programmatically-Update-Layout-Details-with-the-Sitecore-ASPNET-CMS.aspx

http://varunvns.wordpress.com/2012/05/10/sitecore-6-4-functionality-layout-deltas/

Happy Layout Delta Coding! 🙂

PS : Special thanks to Dmitry Belikov (Sitecore Support) for providing this suggestion and Siddhi who did all this investigation and worked on this challenge!

Advertisements

4 Comments

Leave a Comment
  1. Matt / Jun 29 2012 12:20 am

    When I use this method, the device renderings are present, but all their properties are null. eg:

    device.Renderings
    Count = 2
    [0]: {Sitecore.Layouts.RenderingDefinition}
    [1]: {Sitecore.Layouts.RenderingDefinition}
    device.Renderings[0]
    {Sitecore.Layouts.RenderingDefinition}
    base {Sitecore.Xml.Serialization.XmlSerializable}: {Sitecore.Layouts.RenderingDefinition}
    Cachable: null
    Conditions: null
    Datasource: null
    ItemID: null
    MultiVariateTest: null
    Parameters: null
    Placeholder: null
    Rules: null
    UniqueId: “{7E15DA90-AC6B-4996-8033-4DDA2C5541E3}”
    VaryByData: null
    VaryByDevice: null
    VaryByLogin: null
    VaryByParameters: null
    VaryByQueryString: null
    VaryByUser: null
    device.Renderings[1]
    {Sitecore.Layouts.RenderingDefinition}
    base {Sitecore.Xml.Serialization.XmlSerializable}: {Sitecore.Layouts.RenderingDefinition}
    Cachable: null
    Conditions: null
    Datasource: null
    ItemID: null
    MultiVariateTest: null
    Parameters: null
    Placeholder: null
    Rules: null
    UniqueId: “{8A837F96-ADDC-4FE8-8190-FAF740C1FDC2}”
    VaryByData: null
    VaryByDevice: null
    VaryByLogin: null
    VaryByParameters: null
    VaryByQueryString: null
    VaryByUser: null

    The value of the __renderings field looks correct:

    Any ideas?

    I’m running SC 6.5

    • kiranpatils / Jul 26 2012 11:11 pm

      Apologize for delay in reply!

      Can you please send me some more detailed steps to reproduce this issue?

      Kiran

  2. desktop destroyer game / Apr 27 2013 7:47 pm

    Hello there.
    Do you use Twitter? I’d like to follow you but couldn’t
    find the button!

    • kiranpatils / May 1 2013 11:29 pm

      Yes I do!

      You can find it from right side of this blog!

      Keep visiting!

      Sincerely.
      Kiran Patil

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: