Created
November 15, 2018 19:06
-
-
Save GuitarRich/0cb385918e98a0b3ac158e431919699f to your computer and use it in GitHub Desktop.
Generates a Templates.cs struct for a given Sitecore Template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-CleanName() | |
{ | |
param ( | |
[string] $Name | |
) | |
return $Name.Replace(" ", "") | |
} | |
$templateItem = Get-Item . | |
$templateName = Get-CleanName -Name $templateItem.Name | |
Write-Host "public struct Templates" | |
Write-Host "{" | |
Write-Host " public struct $($templateName)" | |
Write-Host " {" | |
Write-Host " public const string Id = ""$($templateItem.ID)"";" | |
Write-Host "" | |
Write-Host " public struct Fields" | |
Write-Host " {" | |
foreach($section in $templateItem.Children) | |
{ | |
foreach($field in $section.Children) | |
{ | |
$fieldName = Get-CleanName -Name $field.Name | |
Write-Host " public const string $($fieldName) = ""$($field.ID)"";" | |
} | |
} | |
Write-Host " }" | |
Write-Host " }" | |
Write-Host "}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this to an SPE Module in a Context Menu item