Copied to clipboard

Flag this post as spam?

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


  • greengiant83 88 posts 109 karma points
    Feb 16, 2011 @ 18:05
    greengiant83
    0

    How to get INode's Master Document Type

    I am getting the current node from umbraco.NodeFactory.Node.GetCurrent()  How can I get the Master Document Type of the node?

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Feb 16, 2011 @ 18:22
    Bo Damgaard Mortensen
    0

    Hi greengiant83,

    What exactly do you mean by Master Document Type? :-) Is it the document type of the current node, or?

    Thanks!

    / Bo

  • greengiant83 88 posts 109 karma points
    Feb 16, 2011 @ 19:37
    greengiant83
    0

    When you make a new DocumentType in umbraco you have the option to specify a Master Document Type.  It seems to work pretty much like object inheritence.  Any custom properties on the Master Document Type are inherited by the new Document Type.  In my case I have a document type of Event and then a few sub types like Sporting Event, Fundraiser, etc, that inherit from the Event sub type.  Further down the line I need my template to be able to walk up the tree node structure to find the event its under.  To do this I think I need to know the nodes master document type.

  • Jesper Hauge 298 posts 487 karma points c-trib
    Mar 16, 2011 @ 13:15
    Jesper Hauge
    0

    Hi Green Giant ;)

    When working with actual document based on a document type, in xslt, razor scripts or the API, there will be no trace of the document type inheritance.

    Each document based on one of the event subdocument types will simply have all the properties from the master document type so if you have:

    Event document type
     - Date property
     - Name property

    Sporting event document type : with event as master document type
     - Sport property

    A published document of type sporting event will have all properties mentioned above

    <!-- In xslt you can do the following when $curentPage is a sporting event -->
    <xsl:value-of select="$currentPage/date" />
    <xsl:value-of select="$currentPage/name" />
    <xsl:value-of select="$currentPage/sport" />
    // Using the NodeFactory in the API you can do this
    var node = umbraco.NodeFactory.Node.GetCurrent();
    string name = node.GetProperty("name").Value;
    DateTime date = DateTime.Parse(node.GetProperty("date").Value); // but use a more safe method like TryParse
    string sport = node.GetProperty("sport").Value;

    Regards
    Jesper Hauge

Please Sign in or register to post replies

Write your reply to:

Draft