1

I have an SXA website with many pages. It has a Home node and quite a lot of items, its children or different SXA settings, refer to it.

I would like to let our editors create a new Home node, enter new content and rebase their current website to this new Home node.

The new Home node is supposed to be based on new template, has different fields, and has a new presentation layer. This is why I would not like to apply all the changes to the existing Home node but create a new one.

As far as I can see there is no a Sitecore Powershell script or command to switch an SXA website to a new Home node easily.

I wonder if anyone has struggled with the same problem and could suggest a way to go.

2
  • 1
    You are planning to change content only for Home item or overall whole site? Dec 9 '19 at 8:40
  • I want to change only content of the Home item. However the links to Home should also be updated in the whole website.
    – i123fr3
    Dec 9 '19 at 8:49
1

As far as I know, Home item is referenced in SXA code either by template or path itself. Therefore I would make interface template with fields that you would like to introduce and create new temporary Home New template which inherits Home template + your newly created interface template.

Create new Home item under original Home item and let editors know what to do to fill it up with content. Once editing is done, add your interface template also to original Home template. Change base template of your new Home item to original Home template. This will be possible without loosing content now as it will have same fields.

Move new Home item on the same level as original Home item and move all items which were under original Home under new Home item. rename original Home item to something else and rename new Home to Home. This should work without affecting any functionality

0

Although rebasing seems to be a quite complex task, I selected the solution that merges 2 home nodes together.

In my case I have the following website structure:

enter image description here

My old home page is called home and the new one has name New Home.

There are 3 main steps implemented in Sitecore Powershell:

  • Create a copy of home and move its /Data/* children to the new copy in case something goes wrong
$database = [Sitecore.Configuration.Factory]::GetDatabase('master')

$oldHome = $database.GetItem('/sitecore/content/Tenant/test/home')
$backupHome = $oldHome.CopyTo($oldHome.Parent, "backup-home", [Sitecore.Data.ID]::New(), $False)
$oldHome.Children["Data"].MoveTo($backupHome)
  • Remove all versions from home since the next step will merge home and New Home together
Remove-ItemVersion $oldHome -Language "*"
  • Merge home and New Home
$newHome = $database.GetItem('/sitecore/content/Tenant/test/New Home')
$xml = $newHome.GetOuterXml($False).Replace($newHome.ID.ToString(), $oldHome.ID.ToString()).Replace('New Home', 'home')

$oldHome.Parent.Paste($xml, $False, [Sitecore.Data.Items.PasteMode] 'Merge')
$newHome.Children["Data"].MoveTo($oldHome)

$newHome.Delete()

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.