我有一个自定义的sitecore按钮,它可以更改当前项目的模板,非常简单.
然而,作为其中的一部分,我还试图将旧布局的渲染转换为新布局,如果它是某种子布局类型的话ItemId.但是ItemId返回的值始终为null,我从中获取的唯一值RenderingDefinition是UniqueId.
我究竟做错了什么?
我曾将此博客文章作为指南.
代码
public class ConvertToNewTemplateCommand : Command
{
protected void Run(ClientPipelineArgs args)
{
if (!SheerResponse.CheckModified())
return;
Item item = Context.ContentDatabase.Items[args.Parameters["id"]];
if (args.IsPostBack)
{
if (args.Result == "yes")
{
//Get current layout details
var originalLayoutXml = item[FieldIDs.LayoutField];
//Get new template
TemplateItem hubTemplate = Context.ContentDatabase.GetTemplate("some guid...");
//Change template
item.ChangeTemplate(hubTemplate);
//Reset laytout
ResetLayout(item);
//Get reset layout
var newLayoutXml = item[FieldIDs.LayoutField];
//Add all the module containers to the new layout in …Run Code Online (Sandbox Code Playgroud)