3

I want to edit some Placeholder settings with Powershell extensions, which involves adding a specific rendering to some and removing another rendering from others.

Is there a simple syntax based on the field type, or should I just use string replacement to edit the field?

7

You can use all Sitecore types to access and manipulate field value. Example

# get your ph settings item
$phSettings = gi -path '/sitecore/layout/Placeholder Settings/content'

# read field and assign it to MultilistField type
[Sitecore.Data.Fields.MultilistField]$field = $phSettings.Fields["Allowed Controls"]

Now you can read and set values

# read IDs from an array of IDs
$field[0]

# replace ID inside an array
$phSettings.Editing.BeginEdit()
$field.Replace("{493B3A83-0FA7-4484-8FC9-4680991CF742}","{493B3A83-0FA7-4484-8FC9-4680991CF743}")
$phSettings.Editing.EndEdit()

MultilistField is an extension of Sitecore.Data.Fields.DelimitedField field type. Decompile it and see other methods available:

  • public int Count
  • public string[] Items
  • public bool Contains(string item)
  • public string Add(string item)
  • public string Remove(string item)
  • public int IndexOf(string item)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.