Copied to clipboard

Flag this post as spam?

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


  • Tim 25 posts 112 karma points
    May 14, 2017 @ 00:29
    Tim
    0

    Content Picker Macro Parameter to IPublishedContent

    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"

  • Alex Skrypnyk 5272 posts 19275 karma points MVP 3x admin c-trib
    May 16, 2017 @ 17:02
    Alex Skrypnyk
    102

    Hi Tim

    Use this code:

    IPublishedContent menuNode1 = Udi.Parse(Model.MacroParameters["NodeID"].ToString()).ToPublishedContent();
    

    And do not forget to use a reference to "Umbraco.Web.Extensions"

  • Robert Foster 393 posts 1459 karma points admin c-trib
    May 24, 2017 @ 22:46
    Robert Foster
    1

    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.

    Rob.

  • Alex Skrypnyk 5272 posts 19275 karma points MVP 3x admin c-trib
    May 25, 2017 @ 07:08
    Alex Skrypnyk
    0

    Hi Robert

    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.

    Alex

  • Aluma 13 posts 106 karma points
    Sep 04, 2017 @ 18:12
    Aluma
    0

    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!

  • Tim 25 posts 112 karma points
    May 16, 2017 @ 17:13
    Tim
    1

    Thanks Alex!

    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.

  • Alex Skrypnyk 5272 posts 19275 karma points MVP 3x admin c-trib
    May 16, 2017 @ 17:14
    Alex Skrypnyk
    0

    Hi Tim

    Glad to help!! Have a great evening!

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft