Copied to clipboard

Flag this post as spam?

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


  • Adriana Cerqueiro 38 posts 177 karma points
    May 16, 2017 @ 16:20
    Adriana Cerqueiro
    0

    New content picker as macro parameter v7.6.1

    Hi everyone,

    Maybe this is something really easy, and I am just not seeing it..

    I just upgraded to 7.6.1 and I'm trying to work with a contentPicker2 as a macro parameter for a macro that goes into the RTE.

    The problem is that when I try to set it in a variable I get an error saying

    Unable to cast object of type 'System.String' to type 'Umbraco.Core.Models.IPublishedContent'
    

    Am I missing something?

    -Adri

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    May 16, 2017 @ 16:23
    Alex Skrypnyk
    0

    Hi Adriana

    Can you show code of your macro?

    Thanks,

    Alex

  • Adriana Cerqueiro 38 posts 177 karma points
    May 16, 2017 @ 16:28
    Adriana Cerqueiro
    0

    Hey, sure

    @helper renderSearchButton() {
    IPublishedContent advancedSearchNodeId = (IPublishedContent)Model.MacroParameters["advancedSearchNodeId"];
    
    <tr>
        <td>
            <a href="" class="button pull-right">
               @advancedSearchNodeId
            </a>
        </td>
    </tr>
    

    If I change it to a string (like I've used other parameters) it prints: umb://document/c7c8c847b85842d5ada827b8759263f8

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    May 16, 2017 @ 16:56
    Alex Skrypnyk
    0

    The issue because Model.MacroParameters["advancedSearchNodeId"]

    ids are in new format.

    You can disable these new uids in umbracoSettings.config EnablePropertyValueConverters set to false - this will help your existing content queries to still work

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    May 16, 2017 @ 16:52
    Alex Skrypnyk
    102

    Hey Adriana

    Use this code please:

    @{
        IPublishedContent advancedSearchNodeId = Udi.Parse(Model.MacroParameters["advancedSearchNodeId"].ToString()).ToPublishedContent();
    }
    

    Thanks,

    Alex

  • Adriana Cerqueiro 38 posts 177 karma points
    May 16, 2017 @ 17:02
    Adriana Cerqueiro
    0

    I think I am missing something else..

    'Umbraco.Core.Udi' does not contain a definition for 'ToPublishedContent' and no extension method 'ToPublishedContent' accepting a first argument of type 'Umbraco.Core.Udi'
    
  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    May 24, 2017 @ 23:50
    Robert Foster
    3

    See the note on a similar forum topic here:

    https://our.umbraco.org/forum/templates-partial-views-and-macros/85703-macro-parameter-to-ipublishedcontent#comment-272529

    Basically, ToPublishedContent() is bad, and will be obsoleted in the very near future (possibly next patch release) and we'll be able to use the standard UmbracoHelper.TypedContent() method and friends instead.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    May 16, 2017 @ 17:03
    Alex Skrypnyk
    1

    Add reference to "Umbraco.Web.Extensions"

    @using Umbraco.Web.Extensions
    

    Alex

  • Adriana Cerqueiro 38 posts 177 karma points
    May 16, 2017 @ 22:00
    Adriana Cerqueiro
    1

    Alex, sorry that I couldn't answer sooner.

    Thanks for the fix! =) It worked!! =)

    Thank you as well for the tip on how to disable the new Content Picker behaviour, I found that answer in another post, but since I'm doing an upgrade on the site either way, I want to be change all the pickers.

    Best regards,

    -Adri

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    May 16, 2017 @ 22:01
    Alex Skrypnyk
    0

    You are welcome, Adriana

    Really glad to help!

Please Sign in or register to post replies

Write your reply to:

Draft