Created: 15 May 2020, last update: 30 Jan 2022
How many times is each rendering used for a specific website
If you want to know how many times each rendering is used for a specific website you can use Sitecore Powershell.
Sitecore has a link database that contains among other links all references of which item a particular rendering uses. So the algorithm you can use is run through all renderings and count the references to the location in the content tree. That is an easy and fast way without parsing the Layout Field to know which rendering are used.
Go the easy way, Sitecore PowerShell has already a build in Report, How many of times is each rendering used? You can found this in /sitecore/shell/ menu, Reporting Tools, PowerShell Reports, How many of times is each rendering used?
See https://doc.sitecorepowershell.com/modules/integration-points/reports
This rapport is a great starting point it gives you all renderings count, if you want it for a specific website in a multi website environment or for a part of the content tree you can modify this.
1) Open PowerShell ISE (You can found this in /sitecore/shell/ menu, Development Tools, PowerShell ISE
2) Copy past the script below.
3) Save as "How many times is each rendering used for a specific website" below Script Library/SPE/Reporting/Content Reports/Reports/Solution Audit
4) That is it, it is ready to run.
<#
.SYNOPSIS
How many times is each rendering used in your solution?
.NOTES
copy from www.stockpick.nl
#>
Import-Function Render-ReportField
filter IsRendering {
# Look for Controller and View renderings
$renderingIds = @("{2A3E91A0-7987-44B5-AB34-35C2D9DE83B9}","{99F8905D-4A87-4EB8-9F8B-A9BEBFB3ADD6}")
if(($renderingIds -contains $_.TemplateID)) { $_; return }
}
$database = "master"
# Renderings Root
$renderingsRootItem = Get-Item -Path "$($database):{32566F0E-7686-45F1-A12F-D7260BD78BC3}"
$websiteRootItem = Get-Item -Path "$($database):{0DE95AE4-41AB-4D01-9EB0-67441B7C2450}"
$props = @{
Parameters = @(
@{Name="websiteRootItem"; Title="Choose the report root"; Tooltip="Only items from this root will be returned."; }
)
Title = "Items With Component Report"
Description = "Choose the website for the report."
Width = 650
Height = 250
ShowHints = $true
Icon = [regex]::Replace($PSScript.Appearance.Icon, "Office", "OfficeWhite", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
}
$result = Read-Variable @props
if($result -eq "cancel") {
exit
}
$items = $renderingsRootItem.Axes.GetDescendants() | Initialize-Item | IsRendering
$reportItems = @()
foreach($item in $items) {
$count = 0
$websitecount = 0;
$referrers = Get-ItemReferrer -Item $item
if ($referrers -ne $null) {
$count = $referrers.Count
foreach($ref in $referrers) {
if ($ref.ItemPath.StartsWith($websiteRootItem.ItemPath)) {
$websitecount++
}
}
}
$reportItem = [PSCustomObject]@{
"Icon" = $item."__Icon"
"Name"=$item.Name
"UsageCount"=$count
"WebsiteCount" = $websitecount
"ItemPath" = $item.ItemPath
"TemplateName" = $item.TemplateName
"Controller" = $item.Controller
}
$reportItems += $reportItem
}
$reportProps = @{
Property = @(
"Icon",@{Name="Rendering Name"; Expression={$_.Name}},
@{Name="Total Number of usages"; Expression={$_.UsageCount}},
@{Name="Number of usages below: "+$websiteRootItem.Name.ToString(); Expression={$_.WebsiteCount}},
"ItemPath",
@{Label="Rendering Type"; Expression={$_.TemplateName} },
"Controller"
)
Title = "Custom rendering report"
InfoTitle = "Available Renderings"
InfoDescription = "Count of references for each rendering. Results include only MVC Controller and View renderings.for" + $websiteRootItem.ItemPath.ToString()
}
$reportItems |
Sort-Object WebsiteCount -Descending |
Show-ListView @reportProps
Close-Window
Note: If your link database is not up to date, you can run the Rebuild link databases from the Control Panel
Note: The role sitecore\Sitecore Client Maintaining is granted access to the reports.
Note: PowerShell Scripts are stored in Sitecore below /sitecore/system/Modules/PowerShell/Script Library (perhaps you want to Unicorn your scripts..)