Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rory 59 posts 84 karma points
    Sep 03, 2011 @ 14:16
    Rory
    0

    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

  • Rory 59 posts 84 karma points
    Sep 03, 2011 @ 14:23
    Rory
    0

    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')
  • Barry 7 posts 94 karma points MVP c-trib
    Mar 09, 2017 @ 07:54
    Barry
    1

    Updated version of this SQL for v7:

        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 
    
  • Jason Prothero 421 posts 1242 karma points c-trib
    Aug 18, 2017 @ 23:18
    Jason Prothero
    1

    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:

    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
    

    Thanks, Jason

Please Sign in or register to post replies

Write your reply to:

Draft