Sitecore 8:通过默认渲染自动填充占位符

Sitecore 8: Automatically fill a placeholder by a default rendering

我正在玩弄动态占位符,并被预填充 concept.Is 震惊了,那里有一种方法可以 select 我的一个占位符的默认呈现,这将避免 "select rendering" 对话框在体验编辑器中 ??

场景:我有一个名为 "PageHead" 的渲染,它包含三个渲染。其中之一是占位符 "PageTeaserPh",目前允许两种渲染:一种是 "PageTeaser",第二种是 "PageTeaserWithImage"。我希望占位符 "PageTeaserPh" 始终将渲染 select 编辑为 "PageTeaser",因此避免出现对话框 "Select rendering" .

我做了一些功课,想知道这是否与标准值有关(我们可以在模板级别拥有它;虽然不确定效果图)而且我也听说过命令模板概念(不深入)。

感谢任何帮助。

您可以在模板的标准值上分配渲染,然后每个新项目都会有您的 PageTeaser 渲染。

如果您想自动执行此过程,请查看 <mvc.getXmlBasedLayoutDefinition> 管道,我们通过扩展此管道来注入通用渲染。

已更新

我找到了一些代码示例和博客文章,它们应该可以帮助您指明正确的方向来处理布局细节。

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();
            }
        }
    }
}

取自此处 - http://www.bugdebugzone.com/2014/06/how-to-add-sublayout-to-sitecore-item.html

还有一些关于该主题的其他博客