0

I have created a custom field type which inherits from general link but has an extra attribute we need. We only want it to be used for a particular microsite. Now I want to write a script so that I could change all the general links for a particular location in the content tree to be my new field type. I'm trying to use $field.Type = "My Custom Link", but getting 'Type' is a ReadOnly property error when I run the script. Is there actually a way to do it via PowerShell?

2 Answers 2

1

To change the Field type of for an item, you need to go to the template of that item and then update the Field Type for that particular field. You can use the below Sitecore Powershell script to traverse through all the templates and find the "General Link" type field and update it to the new type.

$allItems = Get-ChildItem  -Path "master:/sitecore/templates/Sample/Test" -Recurse

$allItems | ForEach-Object {
if ($_.TemplateName -eq 'Template field' -and $_.Type -eq 'General Link' ) {
       $_.Editing.BeginEdit()
        $_.Type = 'Custom General Link'
         $_.Editing.EndEdit()
    }
}
    
2

From what I understand, you have a template with a field which is a link.

Now you want to reuse the template in different parts of your website:

  • you want it to use custom field type, inheriting from General Link in one microsote
  • you want it to use general link in all the other places.

If that's what you want, that is not possible.

You cannot have single template field which will use different field types depending on the location in Sitecore content tree.

1
  • Thank you. I actually don’t know what cloud of dumbness came upon me, I wanted to edit the template and started trying to change it on the content item itself for some reason. Maybe attempting this on a Sunday morning was not the greatest idea. Thank you fot your time again
    – Elena P
    Feb 28 at 2:24

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