Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Item CreatePartialDesign(string partialDesignName)
- {
- // Get the parent item
- var masterDb = Sitecore.Configuration.Factory.GetDatabase("master");
- var parentItem = masterDb.Items["/sitecore/content/My Tenant/My Site/"];
- //Now we need to get the template from which the item is created
- TemplateItem partialDesignTemplate = masterDb.GetTemplate("Project/My Tenant/Partial Design");
- //Now we can add the new item as a child to the parent
- return parentItem.Add(partialDesignName, partialDesignTemplate);
- }
- var partialDesignItem = CreatePartialDesign("New Partial Design");
- string renderingXml = sampleItem["__Renderings"];
- LayoutDefinition layoutDefinition = new LayoutDefinition();
- layoutDefinition.LoadXml(renderingXml);
- string defaultDeviceId = "{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}";
- DeviceDefinition deviceDefinition = layoutDefinition.GetDevice(defaultDeviceId);
- string sampleLayoutId = "{layout-item-guid}";
- deviceDefinition.Layout = sampleLayoutId;
- // Add any renderings you want to a bit like this. You will need the rendering Id's
- string sampleRenderingId = "{rendering-item-guid}";
- RenderingDefinition renderingDefinition = new RenderingDefinition();
- renderingDefinition.ItemID = sampleRenderingId;
- renderingDefinition.Placeholder = "content";
- deviceDefinition.AddRendering(renderingDefinition);
- // Write the presentation back to the renderings field
- string outputXml = layoutDefinition.ToXml();
- sampleItem.Editing.BeginEdit();
- sampleItem["__Renderings"] = outputXml;
- sampleItem.Editing.EndEdit();
Add Comment
Please, Sign In to add comment