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
Trying to figure out how to get from my 'NodeID' parameter on a Macro to a an IPublishedContent object.
Both of the following lines produce Null
IPublishedContent menuNode = Model.Content.GetPropertyValue<IPublishedContent>("NodeID");
IPublishedContent menuNode1 = Umbraco.TypedContent(Model.MacroParameters["NodeID"].ToString());
string test = Model.MacroParameters["NodeID"].ToString();
While the last line produces "umb://document/b7e73eeed6ee48abb8d81076c14f25cb"
Use this code:
IPublishedContent menuNode1 = Udi.Parse(Model.MacroParameters["NodeID"].ToString()).ToPublishedContent();
And do not forget to use a reference to "Umbraco.Web.Extensions"
Just a note on using ToPublishedContent() - this does at least one database call for each id you're trying to resolve...
Edit: There's a Pull Request dealing with this by allowing UmbracoHelper.TypedContent and friends to resolve UDI values to IPublishedContent - this would be the preferred way going forward.
The ToPublishedContent() is obsoleted in this patch as well so once this is out, it shouldn't be used at all.
Thanks for pointing us in right direction. Totally agree with you that UmbracoHelper.TypedContent to resolve UDI will be great, waiting for new version of Umbraco.
Thank you! I was facing the same issue and trying to resolve it for quite some time. This solution worked for me.
However, I do see that IPublishedContent is the preferred way forward. How can we rewrite the solution to implement that? I'm on Umbraco 7.6.3.
Thanks once again!
I posted in the other forum post I found with a similar issue.
This line was returning Null for me, I had to republish the entire site after an upgrade from 7.5.13 to 7.6.1, then it returned as intended.
Glad to help!! Have a great evening!
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted