Copied to clipboard

Flag this post as spam?

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


  • Philip 59 posts 73 karma points
    Jul 07, 2013 @ 15:35
    Philip
    0

    How to get current node i V6

    I just upgraded a project from v. 4.9.0 to v.6.1.x. I am trying to fix the differences in the API, but I have difficulties to something as simple as the current node in a master-page. I have looked in the documentation, but it seem...ummm how to put it, lacking ;)

    I have looked at Umbraco.Core.ApplicationContext.Current.Services.ContentService but I can't seem to find anything which will return the current node?

  • Steven Lemmens 30 posts 71 karma points
    Jul 07, 2013 @ 16:21
    Steven Lemmens
    0

    Where are you trying to load the current node? I believe that in a razor script, you can use CurrentPage to get the current node.

  • Philip 59 posts 73 karma points
    Jul 07, 2013 @ 16:25
    Philip
    0

    It was in a master-page and not a Razor file. 

    I just saw that I could still use umbraco.NodeFactory.Node.GetCurrent() (There was an error, which I mistakenly thought was this line). It just feels wrong to use the old NodeFactory, when there is the new ContentService API.

  • Steven Lemmens 30 posts 71 karma points
    Jul 07, 2013 @ 16:37
    Steven Lemmens
    0

    I believe it is still possible - but probably deprecated. Personally, I always wrap something special in a Macro. If you would wrap it in a Macro, you would get to use the provided property "CurrentPage" or "Model" to access the current Node. 
    I'm sure one of those two will work. 

  • Philip 59 posts 73 karma points
    Jul 10, 2013 @ 13:56
    Philip
    0

    I seems like you basically don't have the current context from outside of a macro, masterpage, usercontrol etc.

  • fabrice 104 posts 227 karma points
    Nov 04, 2014 @ 12:15
    fabrice
    0

    If you don't have access to the current node you can do that with the new API :

    Umbraco.Web.UmbracoHelper umbracoHelper = new Umbraco.Web.UmbracoHelper(UmbracoContext.Current);

    and "umbracoHelper.AssignedContentItem" is your current node as a IPublishedContent

     

Please Sign in or register to post replies

Write your reply to:

Draft