Copied to clipboard

Flag this post as spam?

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


  • Mark 3 posts 23 karma points
    Mar 01, 2013 @ 12:13
    Mark
    0

    Does nodes document type inherit from method

    Is there a method on a DynamicNode in umbraco already to check if the nodes document type inherits from a cirtain document type either by alias or id.

    Or has anyone made an extention method on DynamicNode to make something like:

    bool InheritsFromMyDocType = ((DynamicNode)page).DocTypeInheritsFrom("DocTypeAlias");

    I need it to loop through a number of child pages and only take the ones that inherit from a base document type.

  • Mark 3 posts 23 karma points
    Mar 01, 2013 @ 13:13
    Mark
    0

    Figured out something that seems to work

     

        //umbraco.MacroEngines.DynamicNode

        public static bool IsNodeDocTypeInheritFrom(this DynamicNode node, string documentTypeAlias)

        {

            DocumentType current = DocumentType.GetByAlias(node.NodeTypeAlias);

            while (current.Alias != documentTypeAlias)

            {

                if (current.MasterContentType == -1)

                {

                    return false;

                }

                current = new DocumentType(current.MasterContentType);

            }

            return true;

        }

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 01, 2013 @ 13:27
    Hendy Racher
    0

    Hi Mark,

    Just a thought, how about adding a label property to the master doctype and then checking for it's exitance ? (for example I ofen add a 'isSitePage' property to a base SitePage docType which makes the XPath really simple to get all site pages, or to use the .HasProperty("isSitePage"))

    Hendy

  • Mark 3 posts 23 karma points
    Mar 01, 2013 @ 13:31
    Mark
    0

    Yes you’re right that would have been a much simpler solution with less cycles! I was thinking too much in terms of the umbraco node hierarchy schema.

Please Sign in or register to post replies

Write your reply to:

Draft