Copied to clipboard

Flag this post as spam?

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


  • Sebastian Patten 10 posts 40 karma points
    Dec 14, 2009 @ 18:59
    Sebastian Patten
    0

    Is there such thing as a current node or context item?

    Hi all,

    From working with other CMS's, I have seen the base UserControl (.ascx) extended to include some sort of context that lets you know which node in the tree you are rendering, and allows you to access properties on it.

    Does such a thing exist for Umbraco?

    I'm trying to get at properties on the node through the API.

    Thanks!

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 14, 2009 @ 20:36
    Dirk De Grave
    0

    Hi Sebastian,

    If you need to get at properties on a node, use:

    Document doc = new Document(docId);

    or

    umbraco.presentation.nodeFactory.Node node = new umbraco.presentation.nodeFactory.Node(nodeId);

    (Don't forget to add references to cms, umbraco and businesslogic assemblies)

    Both allow to query the object for properties. Big difference between both api methods is that the latter queries the published xml content (fast/readonly) whereas the first also queries the unpublished content (and hits the database quite frequently)

     

    Does that answer your question, or have I misunderstood the question?

     

    Hope this helps.

    Regards,

    /Dirk

  • Sebastian Patten 10 posts 40 karma points
    Dec 14, 2009 @ 20:36
    Sebastian Patten
    0

    I may have it - Node.GetCurrent(); (using umbraco.presentation.nodeFactory;)

  • Sebastian Patten 10 posts 40 karma points
    Dec 14, 2009 @ 20:38
    Sebastian Patten
    0

    Thanks Dirk - Lots of the documentation use a constructor using an ID, however I was wondering where this ID came from.

    I assume I can find it from Node.GetCurrent()?

    Thanks,

    Seb.

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Dec 14, 2009 @ 22:41
    Aaron Powell
    0

    The current page ID can be accessed through the UmbracoContext - umbraco.presentation.UmbracoContext.Current.PageId

    Make sure you null check it :)

Please Sign in or register to post replies

Write your reply to:

Draft