Pra*_*ade 5 rendering sitecore contentplaceholder sitecore8 experience-editor
我正在玩动态占位符,并被一个预先填充的概念所震撼.有没有办法为我的一个占位符选择默认渲染,这将避免在经验编辑器中的"选择渲染"对话框?
场景:我有一个名为"PageHead"的渲染,它有三个渲染.其中一个是占位符"PageTeaserPh",它目前允许两个渲染:一个是"PageTeaser",第二个是"PageTeaserWithImage".我希望占位符"PageTeaserPh"始终将渲染选为"PageTeaser",因此避免使用"选择渲染"对话框.
我做了一些功课,并想知道这是否与标准值相关(我们可以在模板级别使用它;虽然不能确定渲染)并且我也听说过命令模板概念(不是深入的).
任何和所有帮助表示赞赏.
您可以根据模板的标准值分配渲染,然后每个新项目都将具有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();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
取自这里 - http://www.bugdebugzone.com/2014/06/how-to-add-sublayout-to-sitecore-item.html
还有一些关于该主题的其他博客
归档时间: |
|
查看次数: |
1806 次 |
最近记录: |