Skip to content

Instantly share code, notes, and snippets.

@GuitarRich
Created November 15, 2018 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GuitarRich/0cb385918e98a0b3ac158e431919699f to your computer and use it in GitHub Desktop.
Save GuitarRich/0cb385918e98a0b3ac158e431919699f to your computer and use it in GitHub Desktop.
Generates a Templates.cs struct for a given Sitecore Template
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 "}"
@GuitarRich
Copy link
Author

Add this to an SPE Module in a Context Menu item

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