Programmatically removing sublayouts in Sitecore

后端 未结 1 2036
北恋
北恋 2021-01-19 06:04

Does anyone know how to remove the renderings from a Sitecore item?

I want to remove all of the sublayouts so I can replace them with a new set. I have tried this

相关标签:
1条回答
  • 2021-01-19 06:53

    I think your exception is unrelated. To actually save your changes, you need to edit the item. Be sure you always access and update the value throgh LayoutField.Value.

    LayoutField layoutField = new LayoutField(item.Fields[Sitecore.FieldIDs.LayoutField]);
    LayoutDefinition layout = LayoutDefinition.Parse(layoutField.Value);
    //make your changes to the LayoutDefinition here
    item.Editing.BeginEdit();
    layoutField.Value = layout.ToXml();
    item.Editing.EndEdit();
    
    0 讨论(0)
提交回复
热议问题