Sitecore 8: auto-fill default placeholder

I played with dynamic placeholders and was struck by the concept of prefill. Is there a way to choose the default rendering for one of my placeholders that would avoid the "choose rendering" dialog in the experience editor?

Scenario: I have a rendeing called "PageHead" which has three visualizations. One of them is the PageTeaserPh placeholder, which currently allows two visualizations: one is PageTeaser and the second is PageTeaserWithImage. I want the PageTeaserPh placeholder to always have the rendering selected as PageTeaser, and so avoid the Select Rendering dialog.

I did some homework and wondered if this is related to the Standard values (we can have this at the template level, but are not sure about the visualization), and I also heard about the template command (not in-depth).

Any help is appreciated.

+5
source share
1 answer

You may have a rendering assigned by the default template values, each new item will have a PageTeaser rendering.

If you want to automate this process, look at the <mvc.getXmlBasedLayoutDefinition> pipeline, we will add general visualizations by expanding this pipeline.

Update

I found some code examples and blog entries that should help you in the right direction to manage layout details.

 public void AddSublayoutToItem(string itemId, string sublayoutId) { using (new Sitecore.SecurityModel.SecurityDisabler()) { if (Sitecore.Data.ID.IsID(itemId) && Sitecore.Data.ID.IsID(sublayoutId)) { //Get the master database and get the item on which you want to add sublayout Database masterDatabase = Database.GetDatabase("master"); Item item = masterDatabase.GetItem(Sitecore.Data.ID.Parse(itemId)); // Or you can also get Sitecore Item from Context Database as per your requirement // Item item = Sitecore.Context.Database.GetItem(Sitecore.Data.ID.Parse(itemId)); if (item != null) { // Get the layout definitions and the device definition LayoutField layoutField = new LayoutField(item.Fields[Sitecore.FieldIDs.LayoutField]); LayoutDefinition layoutDefinition = LayoutDefinition.Parse(layoutField.Value); DeviceDefinition deviceDefinition = layoutDefinition.GetDevice(Sitecore.Context.Device.ID.ToString()); //Create a RenderingDefinition and add the reference of sublayout or rendering RenderingDefinition renderingDefinition = new RenderingDefinition(); renderingDefinition.ItemID = sublayoutId; //Set placeholder where the rendering should be displayed renderingDefinition.Placeholder = "content"; // Set the datasource of sublayout, if any renderingDefinition.Datasource = "{24240FF2-B4AA-4EB2-B0A4-63E027934C38}"; // you can also set datasource of sublayout using Sitecore Path // renderingDefinition.Datasource = "/sitecore/content/Home/Books"; //Add the RenderingReference to the DeviceDefinition deviceDefinition.AddRendering(renderingDefinition); // Save the layout changes item.Editing.BeginEdit(); layoutField.Value = layoutDefinition.ToXml(); ; item.Editing.EndEdit(); } } } } 

Taken from here - http://www.bugdebugzone.com/2014/06/how-to-add-sublayout-to-sitecore-item.html

Also several other related blogs

+1
source

Source: https://habr.com/ru/post/1233312/


All Articles