Copied to clipboard

Flag this post as spam?

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


  • Emil Lindgren 28 posts 190 karma points
    Nov 16, 2018 @ 19:22
    Emil Lindgren
    0

    Macro, Content picker sshow selected item.

    Hello,

    I have a question about Macro/ partial View Macro and Contentpicker

    My problem is that when i go in to gridlayout => choose a Macro to put in => choose an item "like the second item", then the first item in the list appears. And its because its "FirstOrDefault()" i only want to show one of them.

        @{
    var selection = Model.Content.Site().FirstChild("blog").Children("blogpost").FirstOrDefault();
    var pickedContent = Model.MacroParameters["productPicker"];
    }
    <div> <p>@selection.Name</p></div>
    

    enter image description here

    So what should i do if i want to display the second one, or the third one? enter image description here

    Thanks Kind regards/ Emil

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Nov 18, 2018 @ 12:59
    Marc Goodson
    100

    Hi Emil

    So when you read the 'picked' blog article id from the macro parameter

    var pickedContent = Model.MacroParameters["productPicker"];
    

    You can then use this id to retrieve the full blog post content from Umbraco, using the Umbraco TypedContent helper eg

        IPublishedContent pickedBlogPost = Umbraco.TypedContent(pickedContent);
    <div> <p>@pickedBlogPost.Name</p></div>
    

    regards

    Marc

  • Emil Lindgren 28 posts 190 karma points
    Nov 27, 2018 @ 15:02
    Emil Lindgren
    0

    Hello Marc, Srry for the late reply. But that was exactly what I searched for. Thank you. Kind regards Eemik

Please Sign in or register to post replies

Write your reply to:

Draft