Skip to content

Instantly share code, notes, and snippets.

@Wesley-Lomax
Created June 13, 2019 13:41
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 Wesley-Lomax/d4477592c7ce93771e55e1cd05f1094d to your computer and use it in GitHub Desktop.
Save Wesley-Lomax/d4477592c7ce93771e55e1cd05f1094d to your computer and use it in GitHub Desktop.
Get count of Sitecore components on layout / page
$item = gi "/sitecore/content/Habitat Sites/Habitat Home/home" -Language 'en'
$sharedLayoutField = $item.Fields[[Sitecore.FieldIDs]::LayoutField]
$finalLayoutField = $item.Fields[[Sitecore.FieldIDs]::FinalLayoutField]
$sharedLayoutXml = [Sitecore.Data.Fields.LayoutField]::GetFieldValue($sharedLayoutField)
$finalLayoutXml = [Sitecore.Data.Fields.LayoutField]::GetFieldValue($finalLayoutField)
$sharedLayout = [Sitecore.Layouts.LayoutDefinition]::Parse($sharedLayoutXml)
$finalLayout = [Sitecore.Layouts.LayoutDefinition]::Parse($finalLayoutXml)
$sharedLayout.Devices[0].Renderings.Count
$finalLayout.Devices[0].Renderings.Count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment