Powershell Logo

Use Sitecore Powershell Console to Find Templates with Layout

Posted 09/12/2012 by techphoria414

Posted in

Undoubtedly someone will tell me an easier way to do this after I post, but was just saved by the Sitecore Powershell Console module yet again. Used it to find references to my base layout underneath /sitecore/templates -- i.e. templates that have a layout assigned on their standard values. Pretty snazzy.

PS master:\layout\Layouts> $layout = get-item BaseLayout
PS master:\layout\Layouts> $linkDatabase = [Sitecore.Globals]::LinkDatabase
PS master:\layout\Layouts> $links = $linkDatabase.GetReferrers($layout)
PS master:\layout\Layouts> $links | foreach-object { if ($_.GetSourceItem() -and $_.GetSourceItem().Paths.Path.ToLower().StartsWith("/sitecore/templates")) { write-host $_.GetSourceItem().Paths.Path } }
/sitecore/templates/snip/Event/Event/__Standard Values  
/sitecore/templates/snip/Generic/Generic Article/__Standard Values  
/sitecore/templates/Branches/snip/Site Root/$name/Home/Products/Categories  
/sitecore/templates/snip/Generic/Generic Detail/__Standard Values  
/sitecore/templates/snip/Education/Category/__Standard Values   
/sitecore/templates/snip/Home/__Standard Values  
/sitecore/templates/snip/Error/__Standard Values  

Looks like I have some branch templates to look at too.