Copied to clipboard

Flag this post as spam?

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


  • Tom 713 posts 954 karma points
    Apr 09, 2010 @ 05:57
    Tom
    0

    Get DocumentType Object and Node Level From umbraco.presentation.nodeFactory.

    Hi All,

    I have a umbraco.presentation.nodeFactory.Node and i want to be able to get a DocumentType object from it.. as well as this I'd like to access the level as well.. I'm trying to work out why these attributes aren't exposed in the Node Class.. and the best work around

     

    Cheers,

    Tom

  • Tom 713 posts 954 karma points
    Apr 09, 2010 @ 07:58
    Tom
    0

    What I'm essentially trying to do is the following:

    I have examine searching a whole pile of nodes.. some of those are nodes used for content holding only (not in a nice layout the user can visit on a page) for example an faq answer.

    So in the search results if the search finds content in the faq answer to display, iterate upwards and find the faq page (which is a descendant of a certain document type)

    I'm trying to get find if the current node is a descendant of a certain document type (aka a page in a nice layout that users can see) and if so use it's link.. if it isn't then check it's parent and see if it is a descendant of a certain document type. I have a Node object and wanted to access it's DocumentType object... alas instead the work around is converting back to XML and checking that.. is there a better way??

     

    string GetPageUrlForPageNode(Node currentNode)
            {
                string result = umbraco.library.NiceUrl(currentNode.Id);
                var nodeAsXml = umbraco.library.GetXmlNodeById(currentNode.Id.ToString());
                var nodeLevel = nodeAsXml.Current.GetAttribute("level","");
                var nodeDocType = nodeAsXml.Current.GetAttribute("nodeType","");
                if (int.Parse(nodeLevel) > 1)
                {
                    DocumentType currentNodeDocumentType = new DocumentType(int.Parse(nodeDocType));
                    while (currentNodeDocumentType != null && currentNodeDocumentType.Text != "Standard Page")
                    {
                        currentNodeDocumentType = (DocumentType)currentNodeDocumentType.Parent;
                    }

                    if (currentNodeDocumentType != null)
                    {
                        return result;
                    }
                    else
                    {
                        result = GetPageUrlForPageNode(currentNode.Parent);
                    }
                }

                return result;
            }

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 09, 2010 @ 11:04
    Lee Kelleher
    2

    Hi Tom,

    Yes, you can use the "NodeTypeAlias" property from the Node object...

    umbraco.presentation.nodeFactory.Node node = umbraco.presentation.nodeFactory.Node.GetCurrent();
    umbraco.cms.businesslogic.web.DocumentType docType = umbraco.cms.businesslogic.web.DocumentType.GetByAlias(node.NodeTypeAlias);
    // do what you like with the 'docType' object

    Cheers, Lee.

  • tentonipete 78 posts 223 karma points
    Jun 16, 2011 @ 11:08
    tentonipete
    0

    Also found this post useful. Thanks

  • John Ligtenberg 53 posts 214 karma points
    Apr 16, 2012 @ 11:53
    John Ligtenberg
    0

    This post helped me to determine the default template of a DocumentType, which I needed to embed nodes in a page.

    var node = new DynamicNode(@link.link);

    umbraco.cms.businesslogic.web.DocumentType docType =
                                      umbraco.cms.businesslogic.web.DocumentType.GetByAlias(node.NodeTypeAlias);

    int template = node.template;
    int defaultTemplate = docType.DefaultTemplate;
    int templateToUse = (template == 0) ? defaultTemplate : template;
    string embeddedContent = umbraco.library.RenderTemplate(node.Id, templateToUse);
Please Sign in or register to post replies

Write your reply to:

Draft