Copied to clipboard

Flag this post as spam?

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


  • Brendan Rice 538 posts 1102 karma points
    Mar 24, 2011 @ 13:26
    Brendan Rice
    0

    TSQL to get Content Nodes associated with a template

    Has anyone got a TSQL query that will get a list of nodes associated to a template, please?

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 24, 2011 @ 13:28
    Hendy Racher
    2

    Hi Brendan,

    Does this forum post help ? There's SQL to get content nodes from a template Id.

    HTH,

    Hendy

  • Brendan Rice 538 posts 1102 karma points
    Mar 24, 2011 @ 13:52
    Brendan Rice
    0

    Perfect, couldn't find a related post, thanks Hendy.

  • Brendan Rice 538 posts 1102 karma points
    Mar 24, 2011 @ 14:08
    Brendan Rice
    0

    Hi Hendy,

    how do you get the template ID, I looked in CMSTemplate and took the node ID. The query seems to return a list of all the content codes associated with the doctype associated with the template. I could do with a filter that only brought back nodes that had a specific template applied.

    Any ideas?

    Thanks,

    Brendan

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 24, 2011 @ 14:18
    Hendy Racher
    1

    Hi Brendan,

    To get the TemplateID, you can hover over the template in the back office and you'll see the ID in the browser status line.

    Alternativily you can look in the cmsTemplate table (the templateId is actually the nodeId).

    Here's an updated script to get the content nodes using template found by the template alias:

    DECLARE @templateId AS int
    SELECT @templateId = nodeId FROM cmsTemplate WHERE alias='Template Alias'

    SELECT C.path AS 'Path',
    C.level AS 'Level',
    C.id AS 'Node Id',
    C.text AS 'Text',
    A.alias AS 'docType Alias'
    FROM cmsContentType A
    LEFT OUTER JOIN cmsContent B ON A.nodeId = B.contentType
    INNER JOIN umbracoNode C ON B.nodeId = C.id
    WHERE A.nodeId IN (
    SELECT contentTypeNodeId
    FROM cmsDocumentType A
    INNER JOIN cmsContentType B ON A.contentTypeNodeId = B.nodeId
    WHERE templateNodeid = @templateId
    )
    ORDER BY text ASC

    HTH,

    Hendy

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 24, 2011 @ 14:21
    Hendy Racher
    1

    Arh, just re-read your post, and yes it'll return all nodes that could potentially use the supplied template. I'll have a go at updating the SQL so it'll only return content nodes with the template defined...

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 24, 2011 @ 14:38
    Hendy Racher
    1

    Hi Brendan,

    How about this:

    DECLARE @templateId AS int
    SELECT @templateId = nodeId FROM cmsTemplate WHERE alias='Template Alias'

    SELECT DISTINCT nodeId
    FROM cmsDocument
    WHERE templateId = @templateId

    HTH,

    Hendy

  • Brendan Rice 538 posts 1102 karma points
    Mar 24, 2011 @ 15:30
    Brendan Rice
    0

    Perfect Hendy thanks a million for the help.

Please Sign in or register to post replies

Write your reply to:

Draft