Copied to clipboard

Flag this post as spam?

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


  • Mikael Mørup 297 posts 326 karma points
    Aug 08, 2009 @ 11:53
    Mikael Mørup
    0

    How to get current document.

    If i use the node factory i can do something like node.getcurrent to get the current node. How can i get the current document using the document API ?

    There is no document.getcurrent method or similar, as far as i cab see.

    I need to use the document API because this code works with unpublished nodes.

    Thanks

    Mikael

  • Mikael Mørup 297 posts 326 karma points
    Aug 08, 2009 @ 12:39
    Mikael Mørup
    2

    Ahh, i think i found it myself:

      int currentNodeId = umbraco.presentation.UmbracoContext.Current.PageId.Value;

    This should work with unpublished nodes right ?

     

    Mikael

  • Masood Afzal 176 posts 522 karma points
    Aug 08, 2009 @ 12:40
    Masood Afzal
    0
    int pageId = ConvertToInt32(HttpContext.Current.Request["pageid"]);
    Document doc = new Document(pageId)
  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Aug 08, 2009 @ 15:44
    Hendy Racher
    0

    how about: Document document = new Document(Node.GetCurrent().Id);

  • Chris Larson 48 posts 63 karma points
    Aug 08, 2009 @ 18:13
    Chris Larson
    1

    No parenthesis on the "GetCurrent" portion of the code. The rest of the code shows a sample of updating, saving and publishing the new content.

    ' Use this to open the document
    Document document = new Document(Node.GetCurrent.ID);
    
    ' Update and save a property value
    Document.getProperty("myProp").Value = myFormObject.Value;
    Document.Save();
    
    ' Publish the document as the root administrator
    Document.Publish(New umbraco.businesslogic.user(0));
    
    ' Update the umbraco cache
    umbraco.library.UpdateDocumentCache(Document.ID);
  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Aug 08, 2009 @ 21:43
    Hendy Racher
    0

    Hi Chris,

    umbraco.presentation.nodeFactroy.Node.GetCurrent() is a method tho ?

    re-reading the original question, I'm not clear on now the current node can ever be an unpublished one ?

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Aug 09, 2009 @ 00:48
    Aaron Powell
    0

    hmm I'm bothered by the fact that there's three perfectly valid yet completely different ways of accessing the ID of the current page (and I do believe there's at least one more :P).

    For the record, going forward the recommended way in which you would be getting it is via the UmbracoContext.Current object. I'd really like only a single one to maintain.

  • Chris Larson 48 posts 63 karma points
    Aug 09, 2009 @ 05:14
    Chris Larson
    0

    Hendy - the assumption (from Mikael's reference above) is that his code has already loaded the unpublished content, though I am not sure where it comes from. By using the API rather than the umbraco core, it is possible to open and read the node regardless of it's published state and still maintain versioning.

    Slace - I think that there might be a problem with existing XSLT functions not being able to reference umbraco.library.pageid as a method of obtaining the current node id. Certainly a consideration before the framework is updated as that could render items developed using that current "best practice" obsolete.

     

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Aug 09, 2009 @ 13:43
    Aaron Powell
    0

    Chris - I'm pretty sure that you'll find that the current page ID is passed into each XSLT OOB, I think it's in the currentId parameter (can't remember rightly, I dont' really use XSLT, I prefer .NET)

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 09, 2009 @ 16:29
    Warren Buckley
    2

    Erm I am not sure if I am following entirely correctly here, but in XSLT to get the currentPage (node) ID is fairly simple:

    <xsl:value-of select="$currentPage/@id" />
  • Aaron Powell 1708 posts 3046 karma points c-trib
    Aug 10, 2009 @ 00:42
    Aaron Powell
    0

    That's it, I knew it was passed into an XSLT somehow :P

  • Chris Larson 48 posts 63 karma points
    Aug 10, 2009 @ 15:01
    Chris Larson
    0

    Is that not a function of the declaration of umbraco.library as an XML namespace at the root of the XSLT document though?

    xmlns:umbraco.library="urn:umbraco.library"
Please Sign in or register to post replies

Write your reply to:

Draft