Guest User

Untitled

a guest
Oct 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. public Item CreatePartialDesign(string partialDesignName)
  2. {
  3. // Get the parent item
  4. var masterDb = Sitecore.Configuration.Factory.GetDatabase("master");
  5. var parentItem = masterDb.Items["/sitecore/content/My Tenant/My Site/"];
  6.  
  7. //Now we need to get the template from which the item is created
  8. TemplateItem partialDesignTemplate = masterDb.GetTemplate("Project/My Tenant/Partial Design");
  9.  
  10. //Now we can add the new item as a child to the parent
  11. return parentItem.Add(partialDesignName, partialDesignTemplate);
  12. }
  13.  
  14. var partialDesignItem = CreatePartialDesign("New Partial Design");
  15. string renderingXml = sampleItem["__Renderings"];
  16. LayoutDefinition layoutDefinition = new LayoutDefinition();
  17. layoutDefinition.LoadXml(renderingXml);
  18.  
  19. string defaultDeviceId = "{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}";
  20. DeviceDefinition deviceDefinition = layoutDefinition.GetDevice(defaultDeviceId);
  21. string sampleLayoutId = "{layout-item-guid}";
  22. deviceDefinition.Layout = sampleLayoutId;
  23.  
  24. // Add any renderings you want to a bit like this. You will need the rendering Id's
  25. string sampleRenderingId = "{rendering-item-guid}";
  26. RenderingDefinition renderingDefinition = new RenderingDefinition();
  27. renderingDefinition.ItemID = sampleRenderingId;
  28. renderingDefinition.Placeholder = "content";
  29. deviceDefinition.AddRendering(renderingDefinition);
  30.  
  31. // Write the presentation back to the renderings field
  32. string outputXml = layoutDefinition.ToXml();
  33. sampleItem.Editing.BeginEdit();
  34. sampleItem["__Renderings"] = outputXml;
  35. sampleItem.Editing.EndEdit();
Add Comment
Please, Sign In to add comment