Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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.
You can use this:
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
IPublishedContent content = umbracoHelper.TypedContent(Node.getCurrentNodeId());
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...
var currentNode = UmbracoContext.Current.PublishedContentRequest.PublishedContent;
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:
UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
IPublishedContent currentPage = umbracoHelper.AssignedContentItem;
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted