Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. function Copy-Page-FinalLayout-To-Template([string]$pagePath,[switch]$ResetLayout){
  2. #get the page item
  3. $item = Get-Item -Path "master:$pagePath"
  4.  
  5. #get the final layout from the page
  6. $finalLayoutField = New-Object -TypeName "Sitecore.Data.Fields.LayoutField" -ArgumentList $Item.Fields[[Sitecore.FieldIDs]::FinalLayoutField]
  7.  
  8. if ($finalLayoutField -eq $null) {
  9. Write-Error "Couldn't find final layout on: $($Item.Name)"
  10. }
  11. if ($finalLayoutField.Value -eq $null -or $finalLayoutField.Value -eq "") {
  12. return;
  13. }
  14.  
  15. #get the items template and standard values on the template
  16. $template = Get-ItemTemplate -ID $item.ID
  17. $templateItem = Get-Item -Path "master:$($template.ID)"
  18. $templateStandardValuesPath = "$($templateItem.Paths.FullPath)/__Standard values";
  19. $standardValuesItem = Get-Item -Path "$($templateItem.Paths.FullPath)/__Standard values"
  20.  
  21. #copy the final layout details back to the the renderings field on the standard values
  22. $finalLayoutDefinition = [Sitecore.Layouts.LayoutDefinition]::Parse($finalLayoutField.Value)
  23. $standardValuesItem.Editing.BeginEdit()
  24. $standardValuesItem["__Renderings"] = $finalLayoutDefinition.ToXml();
  25. $standardValuesItem.Editing.EndEdit()
  26.  
  27. Write-Host "Template Standard Values Updated: $($templateItem.Name)"
  28.  
  29. #reset the page final renderings back to the page templates standard values
  30. if($ResetLayout){
  31. Reset-ItemField -Item $Item -Name "__Final Renderings" -IncludeStandardFields
  32. Write-Host "Page Final Renderings Reset To Standard Values: $($item.Name)"
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement