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.
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?
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!
Hi Sebastian,
If you need to get at properties on a node, use:
or
(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
I may have it - Node.GetCurrent(); (using umbraco.presentation.nodeFactory;)
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.
The current page ID can be accessed through the UmbracoContext - umbraco.presentation.UmbracoContext.Current.PageId
Make sure you null check it :)
is working on a reply...