Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save MartinMiles/633c20c307b39d93025032369b113bb8 to your computer and use it in GitHub Desktop.

Select an option

Save MartinMiles/633c20c307b39d93025032369b113bb8 to your computer and use it in GitHub Desktop.
$ErrorActionPreference = 'Stop'
# ❶ Mount master: drive if absent
if (-not (Get-PSDrive -Name master -ErrorAction SilentlyContinue)) {
New-PSDrive -Name master -PSProvider Sitecore -Root "/" -Database "master" -ErrorAction Stop | Out-Null
}
# ❷ Get master database
$db = [Sitecore.Configuration.Factory]::GetDatabase('master')
if (-not $db) { throw 'Cannot get master database.' }
# ❸ Template-ID constants
$layoutFolderTpl = [Sitecore.Data.TemplateID]::new([Sitecore.Data.ID]::Parse('{7EE0975B-0698-493E-B3A2-0B2EF33D0522}'))
$jsonTpl = [Sitecore.Data.TemplateID]::new([Sitecore.Data.ID]::Parse('{04646A89-996F-4EE7-878A-FFDBF1F0EF0D}'))
$paramFolderTpl = [Sitecore.Data.TemplateID]::new([Sitecore.Data.ID]::Parse('{0437FEE2-44C9-46A6-ABE9-28858D9FEE8C}'))
$paramTplTpl = [Sitecore.Data.TemplateID]::new([Sitecore.Data.ID]::Parse('{AB86861A-6030-46C5-B394-E8F99E8B87DB}'))
$baseFieldId = [Sitecore.Data.ID]::Parse('{12C33F3F-86C5-43A5-AEB4-5598CEC45116}') # __Base template
$placeholdersFieldId = [Sitecore.Data.ID]::Parse('{069A8361-B1CD-437C-8C32-A3BE78941446}') # 'Placeholders' field
# ❹ Root layouts
$layoutRoot = $db.GetItem('/sitecore/layout/Renderings')
if (-not $layoutRoot) { throw 'Missing /sitecore/layout/Renderings' }
# ❺ Your $renderings array
$renderings = @(
[PSCustomObject]@{
RenderingName = "1 Column"
NextComponentName = "1Column"
RenderingDefinitionId = "0AD8EC59-33EC-4103-AAD4-F3A49BFDB92C"
OriginalPath = "/sitecore/layout/Renderings/Project/Common/Section Columns/1 Column"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = "4654D5F0-9B39-426A-992D-1D42E356FB0A"
LayoutServicePlaceholders = "{2E4BDD9E-F7A0-4BB6-8A4F-8A8C1A52E512}|{1A9AED6B-A8C8-41CE-AE0C-99FBC59AE9EE}|{6604D4C8-D30F-46F2-A811-0EEA7F84A6B9}|{B34A4F2B-47CD-4BA6-B1B1-BB62F4090FFD}|{75827361-CE80-4019-B96F-DD5D1CF83F9D}|{42332C9E-A35C-43F3-BC15-29F6F28BEBEE}"
},
[PSCustomObject]@{
RenderingName = "2 Column 3-9"
NextComponentName = "2Column39"
RenderingDefinitionId = "AB7054DD-B8E3-41D6-A75F-B54F2F37D08B"
OriginalPath = "/sitecore/layout/Renderings/Project/Common/Section Columns/2 Column 3-9"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = "4654D5F0-9B39-426A-992D-1D42E356FB0A"
LayoutServicePlaceholders = "{1A9AED6B-A8C8-41CE-AE0C-99FBC59AE9EE}|{75827361-CE80-4019-B96F-DD5D1CF83F9D}"
},
[PSCustomObject]@{
RenderingName = "4 Column 2-2-4-4"
NextComponentName = "4Column2244"
RenderingDefinitionId = "98D6BC34-0185-42A0-B53B-CEB7B17008B6"
OriginalPath = "/sitecore/layout/Renderings/Project/Common/Section Columns/4 Column 2-2-4-4"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = "4654D5F0-9B39-426A-992D-1D42E356FB0A"
LayoutServicePlaceholders = "{1A9AED6B-A8C8-41CE-AE0C-99FBC59AE9EE}|{6604D4C8-D30F-46F2-A811-0EEA7F84A6B9}|{B34A4F2B-47CD-4BA6-B1B1-BB62F4090FFD}|{04C5299E-A260-497D-A436-7DBC51C330B2}"
},
[PSCustomObject]@{
RenderingName = "Article Aside Both"
NextComponentName = "ArticleAsideBoth"
RenderingDefinitionId = "A85A0B65-D3B7-48B8-B362-F17AA3CA7DF1"
OriginalPath = "/sitecore/layout/Renderings/Project/Common/Article Aside Both"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = "4654D5F0-9B39-426A-992D-1D42E356FB0A"
LayoutServicePlaceholders = "{1A9AED6B-A8C8-41CE-AE0C-99FBC59AE9EE}|{6604D4C8-D30F-46F2-A811-0EEA7F84A6B9}|{75827361-CE80-4019-B96F-DD5D1CF83F9D}|{8A11EE66-A1D4-457F-9D76-4694C0E60B2C}"
},
[PSCustomObject]@{
RenderingName = "Article Aside Left"
NextComponentName = "ArticleAsideLeft"
RenderingDefinitionId = "EADA94FA-315F-4DF2-AC49-13346DFDAF12"
OriginalPath = "/sitecore/layout/Renderings/Project/Common/Article Aside Left"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = "4654D5F0-9B39-426A-992D-1D42E356FB0A"
LayoutServicePlaceholders = "{1A9AED6B-A8C8-41CE-AE0C-99FBC59AE9EE}|{75827361-CE80-4019-B96F-DD5D1CF83F9D}|{97C6B5FD-353A-4F98-AD05-919A5547D149}|{8A11EE66-A1D4-457F-9D76-4694C0E60B2C}"
},
[PSCustomObject]@{
RenderingName = "Breadcrumb"
NextComponentName = "Breadcrumb"
RenderingDefinitionId = "E6BA23C6-08F7-43D0-BE00-BB2129D6F288"
OriginalPath = "/sitecore/layout/Renderings/Feature/Navigation/Breadcrumb"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = "{2E4BDD9E-F7A0-4BB6-8A4F-8A8C1A52E512}"
},
[PSCustomObject]@{
RenderingName = "Call to Action"
NextComponentName = "CallToAction"
RenderingDefinitionId = "F7539AE8-F96C-4D93-87A4-CEBA02E6B14F"
OriginalPath = "/sitecore/layout/Renderings/System/Email/Sample Newsletter/Call to Action"
DatasourceLocation = "./"
DatasourceTemplate = "/sitecore/templates/System/Email/Sample Newsletter/Section Content"
Editable = ""
ParametersTemplate = "FD7942B0-B35B-4331-AEDC-929E2C64FA43"
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Child Page List"
NextComponentName = "ChildPageList"
RenderingDefinitionId = "84924ABF-F983-4AF5-9002-EA0237A53DA9"
OriginalPath = "/sitecore/layout/Renderings/Feature/PageContent/Child Page List"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Contact Information"
NextComponentName = "ContactInformation"
RenderingDefinitionId = "CA748838-E6D5-4BAD-9126-CAD10DD1B0DB"
OriginalPath = "/sitecore/layout/Renderings/Feature/Identity/Contact Information"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = "A2A233A1-6701-48A9-B5F8-EFEAB74B655F"
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Content"
NextComponentName = "Content"
RenderingDefinitionId = "75CF2D93-EFF1-46E6-8DBA-575656A62955"
OriginalPath = "/sitecore/layout/Renderings/System/Email/Sample Newsletter/Content"
DatasourceLocation = "./"
DatasourceTemplate = "/sitecore/templates/System/Email/Sample Newsletter/Section Content"
Editable = ""
ParametersTemplate = "FD7942B0-B35B-4331-AEDC-929E2C64FA43"
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Content Teaser with Summary"
NextComponentName = "ContentTeaserWithSummary"
RenderingDefinitionId = "781C6B36-4B02-46EA-8ADC-B92A11877F10"
OriginalPath = "/sitecore/layout/Renderings/Feature/Teasers/Content Teaser with Summary"
DatasourceLocation = "/sitecore/content/Habitat/Settings/Datasources/teasers"
DatasourceTemplate = "/sitecore/templates/Project/Common/Content Types/Teasers/Teaser"
Editable = ""
ParametersTemplate = "A2A233A1-6701-48A9-B5F8-EFEAB74B655F"
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Copyright"
NextComponentName = "Copyright"
RenderingDefinitionId = "7DAE9F23-890F-4E06-99A7-CCEDB74D3D8E"
OriginalPath = "/sitecore/layout/Renderings/Feature/Identity/Copyright"
DatasourceLocation = "/sitecore/content/Habitat/Settings/Datasources/identity"
DatasourceTemplate = "/sitecore/templates/Feature/Identity/_Identity"
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Demo Content"
NextComponentName = "DemoContent"
RenderingDefinitionId = "B883E272-70D8-419A-8AF8-819356D839AD"
OriginalPath = "/sitecore/layout/Renderings/Feature/Demo/Demo Content"
DatasourceLocation = "/sitecore/content/Habitat/Settings/Datasources/democontent"
DatasourceTemplate = "/sitecore/templates/Project/Common/Content Types/Demo Teaser"
Editable = "1"
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Edit Profile"
NextComponentName = "EditProfile"
RenderingDefinitionId = "9B05C591-03CE-4684-9D8A-CCCE99C399ED"
OriginalPath = "/sitecore/layout/Renderings/Feature/Accounts/Edit Profile"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Employee Details"
NextComponentName = "EmployeeDetails"
RenderingDefinitionId = "907018D8-CC53-4D34-AD67-3FDF0A25832A"
OriginalPath = "/sitecore/layout/Renderings/Feature/Person/Employee Details"
DatasourceLocation = "/sitecore/content/Habitat/Settings/Datasources/employee"
DatasourceTemplate = "/sitecore/templates/Feature/Person/_Employee"
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Employee Header"
NextComponentName = "EmployeeHeader"
RenderingDefinitionId = "B6F11192-7C7B-4DE2-9F85-140692B2470B"
OriginalPath = "/sitecore/layout/Renderings/Feature/Person/Employee Header"
DatasourceLocation = "/sitecore/content/Habitat/Settings/Datasources/person"
DatasourceTemplate = "/sitecore/templates/Feature/Person/_Person"
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Employee Header Contact"
NextComponentName = "EmployeeHeaderContact"
RenderingDefinitionId = "C6E4CC96-91AC-4074-AD62-7DAE344F995D"
OriginalPath = "/sitecore/layout/Renderings/Feature/Person/Employee Header Contact"
DatasourceLocation = "/sitecore/content/Habitat/Settings/Datasources/employee"
DatasourceTemplate = "/sitecore/templates/Feature/Person/_Employee"
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Employees List"
NextComponentName = "EmployeesList"
RenderingDefinitionId = "DC19892A-B345-4EFE-AAA2-6E27A801A733"
OriginalPath = "/sitecore/layout/Renderings/Feature/Person/Employees List"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Facebook Open Graph Metadata"
NextComponentName = "FacebookOpenGraphMetadata"
RenderingDefinitionId = "3389CAFC-000C-41E5-921C-92821B3DB7B5"
OriginalPath = "/sitecore/layout/Renderings/Feature/Social/Facebook Open Graph Metadata"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Footer"
NextComponentName = "Footer"
RenderingDefinitionId = "299FD8EA-2CFD-4A69-9CA4-7EA24CD34A46"
OriginalPath = "/sitecore/layout/Renderings/Project/Common/Footer"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = "{97C6B5FD-353A-4F98-AD05-919A5547D149}"
},
[PSCustomObject]@{
RenderingName = "Footer"
NextComponentName = "Footer"
RenderingDefinitionId = "7429DFC1-4BAE-4CDC-BA38-AA7AB27EED33"
OriginalPath = "/sitecore/layout/Renderings/System/Email/Sample Newsletter/Footer"
DatasourceLocation = "./"
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = "FD7942B0-B35B-4331-AEDC-929E2C64FA43"
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Forgot Password"
NextComponentName = "ForgotPassword"
RenderingDefinitionId = "41EA568D-C3AF-45DF-B1D0-B7813CD06093"
OriginalPath = "/sitecore/layout/Renderings/Feature/Accounts/Forgot Password"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Global Search"
NextComponentName = "GlobalSearch"
RenderingDefinitionId = "8C3A2CFC-18FB-4BF5-8584-50EA88978ED6"
OriginalPath = "/sitecore/layout/Renderings/Feature/Search/Global Search"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Header"
NextComponentName = "Header"
RenderingDefinitionId = "7B33308F-2118-4C3C-95A0-F12D389AE5CD"
OriginalPath = "/sitecore/layout/Renderings/System/Email/Sample Newsletter/Header"
DatasourceLocation = "./"
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = "FD7942B0-B35B-4331-AEDC-929E2C64FA43"
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Header Topbar"
NextComponentName = "HeaderTopbar"
RenderingDefinitionId = "C28B9C5F-8E01-42EC-ADF6-3324FAF92C7D"
OriginalPath = "/sitecore/layout/Renderings/Project/Common/Header Topbar"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "HTML Metadata"
NextComponentName = "HtmlMetadata"
RenderingDefinitionId = "E7AE3F87-CF66-40F2-A9F5-33ECF08BC777"
OriginalPath = "/sitecore/layout/Renderings/Feature/Metadata/HTML Metadata"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Image"
NextComponentName = "Image"
RenderingDefinitionId = "13D138CA-D979-4CF0-A664-F647B1E2187D"
OriginalPath = "/sitecore/layout/Renderings/System/Email/Sample Newsletter/Image"
DatasourceLocation = "./"
DatasourceTemplate = "/sitecore/templates/System/Email/Sample Newsletter/Section Content"
Editable = ""
ParametersTemplate = "FD7942B0-B35B-4331-AEDC-929E2C64FA43"
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Language Menu"
NextComponentName = "LanguageMenu"
RenderingDefinitionId = "2695013C-DD51-410B-9983-F271F16C727D"
OriginalPath = "/sitecore/layout/Renderings/Feature/Language/Language Menu"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Latest News"
NextComponentName = "LatestNews"
RenderingDefinitionId = "BDD730EB-F808-4C65-B94A-D2F03672EAFB"
OriginalPath = "/sitecore/layout/Renderings/Feature/News/Latest News"
DatasourceLocation = "/sitecore/content/Habitat/Settings/Datasources/newslist"
DatasourceTemplate = "/sitecore/templates/Project/Habitat/Page Types/News List"
Editable = ""
ParametersTemplate = "A2A233A1-6701-48A9-B5F8-EFEAB74B655F"
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Login"
NextComponentName = "Login"
RenderingDefinitionId = "5899FE6B-2AD7-4243-B1F9-3BC664CF0A7C"
OriginalPath = "/sitecore/layout/Renderings/Feature/Accounts/Login"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Login Menu"
NextComponentName = "LoginMenu"
RenderingDefinitionId = "28BD7068-7FF6-4CE6-98E6-85CFE9967E14"
OriginalPath = "/sitecore/layout/Renderings/Feature/Accounts/Login Menu"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Logo"
NextComponentName = "Logo"
RenderingDefinitionId = "A47C8288-7D4C-45FF-B75F-4AEDBF58A02D"
OriginalPath = "/sitecore/layout/Renderings/Feature/Identity/Logo"
DatasourceLocation = "/sitecore/content/Habitat/Settings/Datasources/identity"
DatasourceTemplate = "/sitecore/templates/Feature/Identity/_Identity"
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Main Navigation"
NextComponentName = "MainNavigation"
RenderingDefinitionId = "E26A158B-FA1E-4E9B-8622-E4458243FF46"
OriginalPath = "/sitecore/layout/Renderings/Project/Common/Main Navigation"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Main Navigation Activity"
NextComponentName = "MainNavigationActivity"
RenderingDefinitionId = "8832BA30-99C3-4D20-9B1C-237D910A153F"
OriginalPath = "/sitecore/layout/Renderings/Project/Common/Main Navigation Activity"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Menu with links"
NextComponentName = "MenuWithLinks"
RenderingDefinitionId = "69B9C355-004B-4268-BB1E-2F725B8752B7"
OriginalPath = "/sitecore/layout/Renderings/Feature/Navigation/Menu with links"
DatasourceLocation = "/sitecore/content/Habitat/Settings/Datasources/linkmenu"
DatasourceTemplate = "/sitecore/templates/Feature/Navigation/_NavigationRoot"
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Navigation Links"
NextComponentName = "NavigationLinks"
RenderingDefinitionId = "F366FBA9-EF26-4007-988A-63CB64649C46"
OriginalPath = "/sitecore/layout/Renderings/Feature/Navigation/Navigation Links"
DatasourceLocation = "/sitecore/content/Habitat/Settings/Datasources/linkmenu"
DatasourceTemplate = "/sitecore/templates/Feature/Navigation/_NavigationRoot"
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "News Article"
NextComponentName = "NewsArticle"
RenderingDefinitionId = "F366176E-2C2B-4AF2-B356-BCF8BD657C58"
OriginalPath = "/sitecore/layout/Renderings/Feature/News/News Article"
DatasourceLocation = "/sitecore/content/Habitat/Settings/Datasources/newsarticle"
DatasourceTemplate = "/sitecore/templates/Project/Habitat/Page Types/News Article"
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "News Content Header Title"
NextComponentName = "NewsContentHeaderTitle"
RenderingDefinitionId = "ABCB6064-2121-4A38-986C-4A21323226AB"
OriginalPath = "/sitecore/layout/Renderings/Feature/News/News Content Header Title"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "News List"
NextComponentName = "NewsList"
RenderingDefinitionId = "6D309FC1-D6B1-43B1-A31C-1FECB7B9303F"
OriginalPath = "/sitecore/layout/Renderings/Feature/News/News List"
DatasourceLocation = "/sitecore/content/Habitat/Settings/Datasources/newslist"
DatasourceTemplate = "/sitecore/templates/Project/Habitat/Page Types/News List"
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "News Related Content"
NextComponentName = "NewsRelatedContent"
RenderingDefinitionId = "692E10B7-6E59-4253-BD64-9A2633FD735F"
OriginalPath = "/sitecore/layout/Renderings/Feature/News/News Related Content"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Page Body"
NextComponentName = "PageBody"
RenderingDefinitionId = "914673DC-FC44-4660-B6EB-FF421FAAC2F9"
OriginalPath = "/sitecore/layout/Renderings/Feature/PageContent/Page Body"
DatasourceLocation = "/sitecore/content/Habitat/Settings/Datasources/pagecontent"
DatasourceTemplate = "/sitecore/templates/Feature/PageContent/_HasPageContent"
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Page Content Header Title"
NextComponentName = "PageContentHeaderTitle"
RenderingDefinitionId = "45B8E1D9-D522-49E0-B9B7-04C965CC7089"
OriginalPath = "/sitecore/layout/Renderings/Feature/PageContent/Page Content Header Title"
DatasourceLocation = "/sitecore/content/Habitat/Settings/Datasources/pagecontent"
DatasourceTemplate = "/sitecore/templates/Feature/PageContent/_HasPageContent"
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Page Header"
NextComponentName = "PageHeader"
RenderingDefinitionId = "A2216CA7-B205-4042-A345-72117D0086C3"
OriginalPath = "/sitecore/layout/Renderings/Project/Common/Page Header"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = "4654D5F0-9B39-426A-992D-1D42E356FB0A"
LayoutServicePlaceholders = "{71DC46A3-311A-4240-9E8A-FA7895CE25E8}|{97C6B5FD-353A-4F98-AD05-919A5547D149}"
},
[PSCustomObject]@{
RenderingName = "Page Header with Media"
NextComponentName = "PageHeaderWithMedia"
RenderingDefinitionId = "26B33DEB-F1DB-4338-B043-AAF2F90E04A3"
OriginalPath = "/sitecore/layout/Renderings/Feature/Media/Page Header with Media"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = "B962A806-D708-4001-B0A3-3FA31F2263C5"
LayoutServicePlaceholders = "{97C6B5FD-353A-4F98-AD05-919A5547D149}"
},
[PSCustomObject]@{
RenderingName = "Page Image Header"
NextComponentName = "PageImageHeader"
RenderingDefinitionId = "359A65BB-0A2C-44E5-8C34-DF3ACDBB42A7"
OriginalPath = "/sitecore/layout/Renderings/Feature/PageContent/Page Image Header"
DatasourceLocation = "/sitecore/content/Habitat/Settings/Datasources/pagecontent"
DatasourceTemplate = "/sitecore/templates/Feature/PageContent/_HasPageContent"
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = "{1A9AED6B-A8C8-41CE-AE0C-99FBC59AE9EE}|{75827361-CE80-4019-B96F-DD5D1CF83F9D}|{97C6B5FD-353A-4F98-AD05-919A5547D149}|{8A11EE66-A1D4-457F-9D76-4694C0E60B2C}|{71DC46A3-311A-4240-9E8A-FA7895CE25E8}|{6604D4C8-D30F-46F2-A811-0EEA7F84A6B9}"
},
[PSCustomObject]@{
RenderingName = "Page Title"
NextComponentName = "PageTitle"
RenderingDefinitionId = "695CEE74-D8F4-481D-B813-237050809290"
OriginalPath = "/sitecore/layout/Renderings/Feature/PageContent/Page Title"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Paged Search Results"
NextComponentName = "PagedSearchResults"
RenderingDefinitionId = "E52D0AE8-2989-44E5-BEA1-EA30C17B2080"
OriginalPath = "/sitecore/layout/Renderings/Feature/Search/Paged Search Results"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = "D1D3E60F-E571-48D2-84CF-B053EE660C13"
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Primary Menu"
NextComponentName = "PrimaryMenu"
RenderingDefinitionId = "53B085DB-6824-4941-9F28-9011CB151832"
OriginalPath = "/sitecore/layout/Renderings/Feature/Navigation/Primary Menu"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = "1"
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Register"
NextComponentName = "Register"
RenderingDefinitionId = "B683EFB4-161D-4FDF-9A90-CC8637766C9C"
OriginalPath = "/sitecore/layout/Renderings/Feature/Accounts/Register"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Search Facets"
NextComponentName = "SearchFacets"
RenderingDefinitionId = "73A3C967-2F70-4847-8B7C-0C214A91FF79"
OriginalPath = "/sitecore/layout/Renderings/Feature/Search/Search Facets"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = "D1D3E60F-E571-48D2-84CF-B053EE660C13"
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Search Results Header"
NextComponentName = "SearchResultsHeader"
RenderingDefinitionId = "D1AAD687-8B93-44C8-9011-8E8CE2DD281F"
OriginalPath = "/sitecore/layout/Renderings/Feature/Search/Search Results Header"
DatasourceLocation = "/sitecore/content/Habitat/Settings/Datasources/searchsettings"
DatasourceTemplate = "{14E452CA-064D-48A8-9FF2-2744D10437A1}"
Editable = ""
ParametersTemplate = "D1D3E60F-E571-48D2-84CF-B053EE660C13"
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Secondary Menu"
NextComponentName = "SecondaryMenu"
RenderingDefinitionId = "3F7AD288-FA57-441F-AD79-CA60DC0C0A8D"
OriginalPath = "/sitecore/layout/Renderings/Feature/Navigation/Secondary Menu"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Section"
NextComponentName = "Section"
RenderingDefinitionId = "D201A487-5099-48A1-8189-55944F70C6CB"
OriginalPath = "/sitecore/layout/Renderings/Project/Common/Section"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = "4654D5F0-9B39-426A-992D-1D42E356FB0A"
LayoutServicePlaceholders = "{97C6B5FD-353A-4F98-AD05-919A5547D149}|{71DC46A3-311A-4240-9E8A-FA7895CE25E8}|{1A9AED6B-A8C8-41CE-AE0C-99FBC59AE9EE}|{75827361-CE80-4019-B96F-DD5D1CF83F9D}|{8A11EE66-A1D4-457F-9D76-4694C0E60B2C}"
},
[PSCustomObject]@{
RenderingName = "Section with Media"
NextComponentName = "SectionWithMedia"
RenderingDefinitionId = "1149A3C7-C69A-4E6B-A6C3-32687EC2F8D4"
OriginalPath = "/sitecore/layout/Renderings/Feature/Media/Section with Media"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = "B962A806-D708-4001-B0A3-3FA31F2263C5"
LayoutServicePlaceholders = "{71DC46A3-311A-4240-9E8A-FA7895CE25E8}|{97C6B5FD-353A-4F98-AD05-919A5547D149}|{1A9AED6B-A8C8-41CE-AE0C-99FBC59AE9EE}|{75827361-CE80-4019-B96F-DD5D1CF83F9D}|{8A11EE66-A1D4-457F-9D76-4694C0E60B2C}"
},
[PSCustomObject]@{
RenderingName = "Site Menu"
NextComponentName = "SiteMenu"
RenderingDefinitionId = "604ECBB6-2BBF-45AF-AC6E-BA9F853E7A03"
OriginalPath = "/sitecore/layout/Renderings/Feature/Multisite/Site Menu"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "Text Message"
NextComponentName = "TextMessage"
RenderingDefinitionId = "D169744B-6343-45D8-831E-658E8560E9CB"
OriginalPath = "/sitecore/layout/Renderings/System/Email/Text Message"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
},
[PSCustomObject]@{
RenderingName = "xDB Panel"
NextComponentName = "XdbPanel"
RenderingDefinitionId = "CED18F24-62C2-445E-B0D9-045E3325297B"
OriginalPath = "/sitecore/layout/Renderings/Feature/Demo/xDB Panel"
DatasourceLocation = ""
DatasourceTemplate = ""
Editable = ""
ParametersTemplate = ""
LayoutServicePlaceholders = ""
}
)
foreach ($r in $renderings) {
# — Parse original path
$segs = $r.OriginalPath.TrimStart('/').Split('/')
$category = $segs[3]
$module = $segs[4]
$rest = $segs[5..($segs.Length - 1)]
# — Build target layout path
$targetSegs = @('sitecore','layout','Renderings',$category,'Zont',$module) + $rest
$targetPath = '/' + ($targetSegs -join '/')
# — Create missing layout folders
$parent = $layoutRoot
$folderParts = $targetSegs[3..($targetSegs.Length - 2)]
foreach ($f in $folderParts) {
$child = $parent.Children[$f]
if (-not $child) {
$child = $parent.Add($f, $layoutFolderTpl)
Write-Host "Created layout folder: $($child.Paths.FullPath)"
}
$parent = $child
}
# — Create or fetch the JSON rendering item
$itemName = $targetSegs[-1]
$renderItem = $parent.Children[$itemName]
if (-not $renderItem) {
$renderItem = $parent.Add($itemName, $jsonTpl, [Sitecore.Data.ID]::Parse($r.RenderingDefinitionId))
Write-Host "Created rendering: $($renderItem.Paths.FullPath)"
} else {
Write-Host "Rendering exists: $($renderItem.Paths.FullPath)"
}
# — Build and link parameter-template under /sitecore/templates
$tplParts = @($category,'Zont','Habitat',$module,'Rendering Parameters')
$node = $db.GetItem('/sitecore/templates')
foreach ($p in $tplParts) {
$child = $node.Children[$p]
if (-not $child) {
$child = $node.Add($p, $paramFolderTpl)
Write-Host "Created template folder: $($child.Paths.FullPath)"
}
$node = $child
}
$paramName = $itemName
$paramItem = $node.Children[$paramName]
if (-not $paramItem) {
$paramItem = $node.Add($paramName, $paramTplTpl)
Write-Host "Created parameters template: $($paramItem.Paths.FullPath)"
} else {
Write-Host "Parameters template exists: $($paramItem.Paths.FullPath)"
}
# — Set __Base template
$defaults = @(
'{5C74E985-E055-43FF-B28C-DB6C6A6450A2}',
'{44A022DB-56D3-419A-B43B-E27E4D8E9C41}',
'{3DB3EB10-F8D0-4CC9-BE26-18CE7B139EC8}',
'{4247AAD4-EBDE-4994-998F-E067A51B1FE4}'
)
if ($r.ParametersTemplate) { $defaults += $r.ParametersTemplate }
$joined = $defaults -join '|'
$paramItem.Editing.BeginEdit()
$paramItem.Fields[$baseFieldId].Value = $joined
$paramItem.Editing.EndEdit()
Write-Host "Set __Base template on $($paramItem.Paths.FullPath) to: $joined"
# — Link parameters template to rendering
if ($renderItem.Fields['Parameters Template']) {
$renderItem.Editing.BeginEdit()
$renderItem.Fields['Parameters Template'].Value = $paramItem.ID.ToString()
$renderItem.Editing.EndEdit()
Write-Host "Linked Parameters Template: $($paramItem.Paths.FullPath)"
} else {
Write-Warning "Missing 'Parameters Template' field on $($renderItem.Paths.FullPath)"
}
# — Update rendering-definition fields
$renderItem.Editing.BeginEdit()
$renderItem['componentName'] = $r.NextComponentName
$renderItem['Datasource Location'] = $r.DatasourceLocation
$renderItem['Datasource Template'] = $r.DatasourceTemplate
$renderItem['Editable'] = $r.Editable
$renderItem['Enable Datasource Query'] = '1'
$renderItem.Editing.EndEdit()
Write-Host "Updated rendering fields: $($renderItem.Paths.FullPath)"
# — **NEW**: write LayoutServicePlaceholders into the 'Placeholders' field
if ($r.LayoutServicePlaceholders) {
$renderItem.Editing.BeginEdit()
$renderItem.Fields[$placeholdersFieldId].Value = $r.LayoutServicePlaceholders
$renderItem.Editing.EndEdit()
Write-Host "Set 'Placeholders' on $($renderItem.Paths.FullPath) to: $($r.LayoutServicePlaceholders)"
}
}
Write-Host "Batch process complete."
You are a world-renowned Sitecore XM Cloud scripting expert. Write an inline Sitecore PowerShell Extensions (SPE) script, ready to paste into Sitecore PowerShell ISE, that batch processes a `$renderings` collection of PSCustomObject with properties:
- `RenderingName`
- `NextComponentName`
- `RenderingDefinitionId`
- `OriginalPath` (e.g. `/sitecore/layout/Renderings/Project/Common/...`)
- `DatasourceLocation`
- `DatasourceTemplate`
- `Editable`
- `ParametersTemplate` (GUID or empty)
The script must:
1. Set `$ErrorActionPreference = 'Stop'`.
2. Mount the `master:` PSDrive if absent.
3. Get the master database via `[Sitecore.Configuration.Factory]::GetDatabase('master')`.
4. Define these template IDs:
- Rendering Folder: `{7EE0975B-0698-493E-B3A2-0B2EF33D0522}`
- JSON Rendering: `{04646A89-996F-4EE7-878A-FFDBF1F0EF0D}`
- Template Folder: `{0437FEE2-44C9-46A6-ABE9-28858D9FEE8C}`
- Template: `{AB86861A-6030-46C5-B394-E8F99E8B87DB}`
- Base-template field ID: `{12C33F3F-86C5-43A5-AEB4-5598CEC45116}`
5. For each `$r` in `$renderings`:
- Parse `OriginalPath` by splitting on `/`; let `category` be segment 4 (Project/Feature/Foundation/System), `module` be segment 5, and the rest be subfolders/item.
- Under `/sitecore/layout/Renderings/{category}/Zont/{module}/…`, recreate any missing folders with the Rendering Folder template and `Write-Host`.
- Create or fetch the JSON rendering item in the final folder using the JSON Rendering template and the GUID from `RenderingDefinitionId`; `Write-Host`.
- Under `/sitecore/templates/{category}/Zont/Habitat/{module}/Rendering Parameters`, recreate any missing folders with the Template Folder template; `Write-Host`.
- Create or fetch the parameters template item named `$r.RenderingName` using the Template template; `Write-Host`.
- Build a pipe-separated list of these GUIDs in this exact order:
1. `{5C74E985-E055-43FF-B28C-DB6C6A6450A2}`
2. `{44A022DB-56D3-419A-B43B-E27E4D8E9C41}`
3. `{3DB3EB10-F8D0-4CC9-BE26-18CE7B139EC8}`
4. `{4247AAD4-EBDE-4994-998F-E067A51B1FE4}`
5. `$r.ParametersTemplate` if non-empty
- In a `BeginEdit()`/`EndEdit()` block, set the shared `__Base template` field (by ID) to that list, then `Write-Host`.
- In a `BeginEdit()`/`EndEdit()` block, set the rendering item’s **Parameters Template** field to the parameters template’s ID; `Write-Host`.
- In a `BeginEdit()`/`EndEdit()` block, set:
- `componentName` = `$r.NextComponentName`
- `Datasource Location` = `$r.DatasourceLocation`
- `Datasource Template` = `$r.DatasourceTemplate`
- `Editable` = `$r.Editable`
- `Enable Datasource Query` = `1`
then `Write-Host`.
6. Use only native Sitecore API calls (`GetDatabase`, `Add()`, `BeginEdit()`, `EndEdit()`, item indexer for fields). Do not use SPE helper cmdlets.
7. Output only the final PowerShell script block.
@MartinMiles
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment