Copied to clipboard

Flag this post as spam?

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


  • Topic author was deleted

    Aug 17, 2013 @ 22:04

    V6 how to get 'current' node (when not on a View)?

    Getting the current node on the Views is easy.

    But how would one get the 'current' node from the ApplicationContext in v6 while not on a view?

    Umbraco.Core.ApplicationContext.Current.Services.ContentService...

    v4 has this:

    umbraco.NodeFactory.Node.GetCurrent();

     

     

  • Comment author was deleted

    Aug 17, 2013 @ 22:12

    I see plenty of 'GetById' and what not's, but I don't see a current.  The idea here is I need the currently executing Content because I don't know the ID.

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Aug 17, 2013 @ 22:40
    Morten Christensen
    100

    The various services (ie. ContentService) doesn't have a context of what is 'current'. You need the UmbracoContext for that. And if you just want the Id of the current page in order to 'get' something from the ContentService you should be able to use Umbraco.Web.UmbracoContext.Current.PageId (there are a few other ways to go about this but it depends on what you want to do, and since you explicitly mention the ContentService I wouldn't throw IPublishedContent/IPublishedContentRequest into the mix).

    Remember that the ContentService is something we want to be able to use from various contexts ie. the backoffice, a controller, web service etc. for doing crud type operations for stuff like content and media, so it wouldn't make sense to have these services aware of a 'current context'.

    Hope that makes sense.

    / Morten

  • Comment author was deleted

    Aug 17, 2013 @ 22:49

    Thanks Morten.  V6 is a bit fuzzier for me than v4 was.  #h5yr

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Aug 17, 2013 @ 23:15
    David Brendel
    0

    Also there is the Umbraco.AssignedContentItem property that you can use if you have the UmbracoContext.

    (hope i spelled it right)

Please Sign in or register to post replies

Write your reply to:

Draft