How to get a list of templates and what pages use them
I have a multiple hierarchical template structure for my site, with many different templates. For documenting the site, I would like to have a list of which templates in the site are used by which page.
In Umbraco I know I can go to each page in the Content section, select that page, then check which template it is using...but it would be much easier if I can view a list of "pages by template" or "templates by pages" somewhere.
Is this possible?
I realise I probably have several redundant templates, and I want to tidy it up and rationalise it, but I don't want to delete a template then find a page is broken somewhere!
Ok, so I think I've answered my own question here, by using SQL in the Umbraco database. If anyone has a better answer I'd be glad to hear it.
SELECT dbo.cmsDocument.nodeId, dbo.cmsDocument.text, dbo.cmsTemplate.master, dbo.cmsTemplate.alias AS Template FROM dbo.cmsDocument INNER JOIN dbo.cmsTemplate ON dbo.cmsDocument.templateId = dbo.cmsTemplate.nodeId WHERE (dbo.cmsDocument.published = '1')
SELECT dbo.cmsDocument.nodeId, dbo.cmsDocument.text, dbo.cmsTemplate.alias, dbo.cmsTemplate.alias AS Template FROM dbo.cmsDocument INNER JOIN
dbo.cmsTemplate ON dbo.cmsDocument.templateId = dbo.cmsTemplate.nodeId
WHERE (dbo.cmsDocument.published = '1')
ORDER BY Template
You can also filter specific Template alias easily by doing:
SELECT dbo.cmsDocument.nodeId, dbo.cmsDocument.text, dbo.cmsTemplate.alias, dbo.cmsTemplate.alias AS Template
FROM dbo.cmsDocument INNER JOIN
dbo.cmsTemplate ON dbo.cmsDocument.templateId = dbo.cmsTemplate.nodeId
WHERE (dbo.cmsDocument.published = '1')
and (dbo.cmsTemplate.alias = 'YourTemplateAlias')
ORDER BY Template
If you are interested in a list that gives you an idea of the Templates that are used and a count of how often, this may be helpful:
SELECT tt.alias as template_name,
tt.nodeId as template_id,
(SELECT COUNT(dbo.cmsDocument.nodeId) FROM dbo.cmsDocument
WHERE dbo.cmsDocument.templateId = tt.nodeId
AND dbo.cmsDocument.published = '1'
) as published_node_count
FROM dbo.cmsTemplate tt
ORDER BY published_node_count DESC
SELECT
n.text AS DocumentTypeName,
t.alias AS TemplateName
FROM
umbracoNode n
INNER JOIN
cmsDocumentType dt ON n.id = dt.contentTypeNodeId
INNER JOIN
cmsTemplate t ON dt.templateNodeId = t.nodeId
ORDER BY
DocumentTypeName;
and for a specific template
SELECT
n.text AS DocumentTypeName,
t.alias AS TemplateName
FROM
umbracoNode n
INNER JOIN
cmsDocumentType dt ON n.id = dt.contentTypeNodeId
INNER JOIN
cmsTemplate t ON dt.templateNodeId = t.nodeId
WHERE
t.alias = 'TemplateAlias'
ORDER BY
DocumentTypeName;
How to get a list of templates and what pages use them
I have a multiple hierarchical template structure for my site, with many different templates. For documenting the site, I would like to have a list of which templates in the site are used by which page.
In Umbraco I know I can go to each page in the Content section, select that page, then check which template it is using...but it would be much easier if I can view a list of "pages by template" or "templates by pages" somewhere.
Is this possible?
I realise I probably have several redundant templates, and I want to tidy it up and rationalise it, but I don't want to delete a template then find a page is broken somewhere!
Thanks
Rory
Ok, so I think I've answered my own question here, by using SQL in the Umbraco database. If anyone has a better answer I'd be glad to hear it.
Updated version of this SQL for v7:
You can also filter specific Template alias easily by doing:
Thanks Barry for the updated post!
If you are interested in a list that gives you an idea of the Templates that are used and a count of how often, this may be helpful:
Thanks, Jason
Here it is for v10 (and probably v9)
and for a specific template
is working on a reply...