Return to doc.sitecore.com

Valid for Sitecore 5.3.1
10.  Layout
Prev Next

The complex field type, Lookup are stored in a field as text with the following format: 

<r ><d id="{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}" l="{14030E9F-CE92-49C6-AD87-7D49B50E42EA}"><r id="{493B3A83-0FA7-4484-8FC9-4680991CF743}" ph="content" ds="" par="Param1=Value1" cac="1" vbd="1" vbu="1" /></d><d id="{46D2F427-4CE5-4E1F-BA10-EF3636F43534}" l="{14030E9F-CE92-49C6-AD87-7D49B50E42EA}"><r id="{5D104030-657E-48DA-B032-0F9BB1A3C671}" ph="content" ds="" par="" /><r id="{E0E16B09-0176-4756-978C-63459B19F8ED}" ph="content" ds="/sitecore/content/Home/Other selectable document" par="Param1=Paramvalue1&amp;Param2=Paramvalue2" cac="1" vbdev="1" vbqs="1" /></d></r>

Resolve the value by using implicit casting

public static string outLayout(Sitecore.Data.Items.Item item, string sFieldName)
{
  System.Text.StringBuilder builder
= new System.Text.StringBuilder();
  
  
// cast field to LayoutField object
  Sitecore.Data.Fields.LayoutField layoutField = item.Fields[sFieldName];
  
  
// We want to resolve all devices.
  Sitecore.Data.Items.DeviceItem[] deviceitems =
    Sitecore.Configuration.Factory.GetDatabase(
"master").Resources.Devices.GetAll();
  
  
foreach (Sitecore.Data.Items.DeviceItem deviceitem in deviceitems)
  {
    builder.Append(
"<strong>Device: " + deviceitem.Name + "</strong>");
    builder.Append(
"<br />");

    Sitecore.Data.ID layoutid
= layoutField.GetLayoutID(deviceitem);
    
    
if (layoutid.IsNull)
    {
      builder.Append(
" * NO LAYOUT!");
      builder.Append(
"<br />");
    }
    
else
    {
      Sitecore.Data.Items.Item layoutitem
= Sitecore.Configuration.Factory.GetDatabase("master").Items[layoutid];
      builder.Append(
"<u>Layout : " + layoutitem.DisplayName + "</u>");          
      builder.Append(
"<br />");

      Sitecore.Layouts.RenderingReference[] renderingReferences
= layoutField.GetReferences(deviceitem);
    
      
if (renderingReferences!=null)
      {                    
        
foreach (Sitecore.Layouts.RenderingReference renderingReference in renderingReferences)
        {              
          builder.Append(
"Rendering: " + renderingReference.RenderingItem.Name);            
          builder.Append(
"<br />");
          builder.Append(
"placeholder = " + renderingReference.Placeholder);
          builder.Append(
"<br />");
          builder.Append(
"parameters = " + renderingReference.Settings.Parameters);
          builder.Append(
"<br />");
        }
      }          
    }
  }    
  
return builder.ToString();
}

Result:

Device: Default
Layout : Document
Rendering: Document
placeholder = content
parameters = Param1=Value1
Device: IE 6.0
* NO LAYOUT!
Device: Print
Layout : Document
Rendering: Form.01 Quiz
placeholder = content
parameters =
Rendering: SimpleMenu
placeholder = content
parameters = Param1=Paramvalue1&Param2=Paramvalue2

 


Prev Next