Copied to clipboard

Flag this post as spam?

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


  • Accusoft 58 posts 109 karma points
    Sep 10, 2012 @ 19:25
    Accusoft
    0

    Node data from unpublished Node?

    I'm writing a script that displays content Nodes.  However, some of them may not be published.  If the node is published, I get back all the data I need:

    Node activeNode = new Node(1121);
    @activeNode.Name
    @activeNode.GetProperty("tags").Value

    However, when the Node is unpublished, all this data comes back blank or null.  How can I get the data even if it's unpublished?

  • Douglas Ludlow 210 posts 366 karma points
    Sep 10, 2012 @ 20:02
    Douglas Ludlow
    3

    Hey Chris,

    You'll want to be using Document then in this case. See Difference between Node and Document. Basically Node only gets the published items that are in the umbraco.config cache file. Document actually reflects what information is available in the database. Note that because it accesses the database, there will be a perfomance hit when your code is processed, so you may want to approach your problem in a different way.

    Regardless, you can access Document properties very simular to how to access Node properties. It looks like you are attempting to do this with razor, so:

    Document activeNode = new Document(1121);

    // Output the name of the node:
    @activeNode.Text
    <br />

    // Output the tags value: (Note: lower case on getProperty is intentional.)
    @activeNode.getProperty("tags").Value
  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Sep 10, 2012 @ 21:22
    Richard Soeteman
    0

    Why would you display unpublished data? It is possible to use the document object as suggested but that will hit the database and really slow down performance. So you might want to rethink your solution to make sure the site performs.

    Cheers,

    Richard

  • Accusoft 58 posts 109 karma points
    Sep 11, 2012 @ 15:40
    Accusoft
    0

    @Douglas - thanks, worked perfect!

    @Ricahrd - it's custom code I'm putting together that I need to work in preview mode.  I'm going to use Node for normal operation, but if it passes a specific ID I'll know it's preview mode and use Document to accommodate that view.  It'll be used so minimally that it shouldn't have an impact.

    Really appreciate the help!

Please Sign in or register to post replies

Write your reply to:

Draft