Apologies if this has been asked before but I'm struggling to find any documentation for what I'm looking for. I have already looked at this section...
In Umbraco 4.7+ you could do something like this to get access to the current node using DynamicNode...
var Node = Node.GetCurrent();
var DynamicNode = new DynamicNode(Node.Id);
In Umbraco 6, with MVC this was replaced with IPublishedContent. So, the question is how would you do something like the above to get the current node as an IPublishedContent object?
Note, I am not talking about Razor views and want to do this in a helper class of some sort.
Thanks Erik, I like the UmbracoHelper object. Looks very useful!
In searching around though, we can do better...
On a controller that inherits from SurfaceController, you actually have access to the CurrentPage object that is exposed in the views so don't need to call Node.getCurrentNodeId()
And outside of that scope (in 6.1+) you can use...
var currentNode = UmbracoContext.Current.PublishedContentRequest.PublishedContent;
Get current node as IPublishedContent
Hi all,
Apologies if this has been asked before but I'm struggling to find any documentation for what I'm looking for. I have already looked at this section...
http://our.umbraco.org/Documentation/Reference/Mvc/querying
In Umbraco 4.7+ you could do something like this to get access to the current node using DynamicNode...
In Umbraco 6, with MVC this was replaced with IPublishedContent. So, the question is how would you do something like the above to get the current node as an IPublishedContent object?
Note, I am not talking about Razor views and want to do this in a helper class of some sort.
Thanks Tom
You can use this:
Alternatively, if you're on a controller that inherits from SurfaceController, you can just do this:
Thanks Erik, I like the UmbracoHelper object. Looks very useful!
In searching around though, we can do better...
On a controller that inherits from SurfaceController, you actually have access to the CurrentPage object that is exposed in the views so don't need to call Node.getCurrentNodeId()
And outside of that scope (in 6.1+) you can use...
See this post for a more detailed discussion: http://our.umbraco.org/forum/developers/api-questions/37894-new-Dynamic(id)-and-new-Node(id)-equiv-in-v6?p=5
In a helper method you can also use this:
see: https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/
;-)
is working on a reply...