I'm working on a script to modify rendering parameters. I noticed that I seem to only be able to modify the Shared Layout and not the Final Layout. I can retrieve the Final Layout field and work based off of it, but in order to apply the changes, item[Sitecore.FieldIDs.LayoutField] = layoutDefinition.ToXml();
works but item[Sitecore.FieldIDs.FinalLayoutField] = layoutDefinition.ToXml();
I am concerned about modifying the Shared Layout having unintended consequences from modifying the shared layout instead of the Final Layout, as language versions may have different renderings and I don't want to overwrite language-specific renderings.
This updates my layout (both Shared and Final):
var layoutField = new LayoutField(item.Fields[Sitecore.FieldIDs.FinalLayoutField]);
var layoutDefinition = LayoutDefinition.Parse(layoutField.Value);
var deviceDefinition = layoutDefinition.GetDevice(defaultDeviceId);
<stuff to modify the renderings>
item.Editing.BeginEdit();
item[Sitecore.FieldIDs.LayoutField] = layoutDefinition.ToXml();
item.Editing.EndEdit();
This does not appear to update anything:
var layoutField = new LayoutField(item.Fields[Sitecore.FieldIDs.FinalLayoutField]);
var layoutDefinition = LayoutDefinition.Parse(layoutField.Value);
var deviceDefinition = layoutDefinition.GetDevice(defaultDeviceId);
<stuff to modify the renderings>
item.Editing.BeginEdit();
item[Sitecore.FieldIDs.FinalLayoutField] = layoutDefinition.ToXml();
item.Editing.EndEdit();
EDIT: I am not just trying to modify rendering parameter field values but also need to be able to move a rendering's position and to change its placeholder.