Copied to clipboard

Flag this post as spam?

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


  • Steven Wilber 103 posts 98 karma points
    Feb 15, 2010 @ 12:42
    Steven Wilber
    0

    How to tell if a Content node is published?

    Hi guys,

    Does anyone know of the "proper" way to tell if a Content object is published.

    The two options that I can see are:

    a) Create a Document object based on the ID of the Content object and check its Published property - this seems to involve an unnecessary creation of a Document object for such a simple check

    b) Check if the path starts with "-1" - this seems to be a bit of a hacky way that may not be future proof.

    So it is perfectly possible, I just wondered what the "proper" cheap way is.

    Cheers

    Steve

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Feb 15, 2010 @ 12:53
    Peter Dijksterhuis
    1

    Hi Steve,

    simple, if you use XSLT to view the Content, all you get IS published. The umbraco.config-file (which is used when you use XSLT) does not contain unpublished nodes.

    If you do want unpublished nodes, then, yes, the only way I know of is to create the document.

    HTH,

    Peter

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 15, 2010 @ 13:04
    Dirk De Grave
    2

    Peter's right, if it can't be found using

    Node node = new Node(id);

    then it's not published. If you really need to have info on the node, use 

    Document doc = new Document(id);

    (be aware that this latter requires quite some db traffic, so don't use this in the frontend unless it's absolutely necessary)

     

    Cheers,

    /Dirk

     

  • Steven Wilber 103 posts 98 karma points
    Feb 17, 2010 @ 13:43
    Steven Wilber
    0

    Hi Guys,

    Thanks for the responses. I'm not in XSLT, just plain C#, so the Node node = new Node(id) seems the best way to go.

    Inadvertantly Dirk you've brought to my attention the cost of the Document object, which I had not realised, so thanks for that.

    Cheers

    Steve

Please Sign in or register to post replies

Write your reply to:

Draft