我正在摆弄动态占位符,并对预填充概念感到震惊。有没有一种方法可以为我的占位符之一选择默认渲染,从而避免体验编辑器中的“选择渲染”对话框?
场景:我有一个名为“PageHead”的渲染,它具有三个渲染。其中之一是占位符“PageTeaserPh”,当前允许两种渲染:第一个是“PageTeaser”,第二个是“PageTeaserWithImage”。我希望占位符“PageTeaserPh”始终将渲染选择为“PageTeaser”,因此避免出现“选择渲染”对话框。
我做了一些作业,想知道这是否与以下有关标准值(我们可以在模板级别使用它;但不确定渲染效果)而且我也听说过命令模板概念(不深入)。
任何和所有的帮助表示赞赏。
您可以根据模板的标准值分配渲染,然后每个新项目都会有您的页面预告片渲染。
如果您想自动化此过程,请查看<mvc.getXmlBasedLayoutDefinition>
管道,我们通过扩展该管道来注入常见的渲染。
Updated
我找到了一些代码示例和博客文章,它们应该可以帮助您指明操作布局细节的正确方向。
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 http://www.bugdebugzone.com/2014/06/how-to-add-sublayout-to-sitecore-item.html
还有一些关于该主题的其他博客
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)