How to get a spreadsheet of Sitecore template usage

I wanted to get an overview of all the templates in a Sitecore project along with how many times each has been used.

I thought there might be some marketplace module for doing this but couldn’t find one, nor could I find a suitable report in the ASR module.

So I wrote a little aspx script to write this out, hopefully it will be useful to someone:

<%@ Page Language="C#" AutoEventWireup="true" %><%

Response.ContentType = "text/csv";
var db = Sitecore.Data.Database.GetDatabase("master");
var templates = db.GetItem("/sitecore/templates/User Defined");
foreach (var template in templates.Axes.GetDescendants())
{
	if (template.TemplateName == "Template")
	{
		var usage = Sitecore.Globals.LinkDatabase.GetReferrerCount(template);

		if (template.Children["__Standard Values"] != null)
			usage--;

		Response.Write(template.ID + "," + template.Paths.Path + "," + usage + "," + Environment.NewLine);
	}
}

%>

Leave a Reply

Your email address will not be published. Required fields are marked *