Copied to clipboard

Flag this post as spam?

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


  • Jay Crowe 42 posts 173 karma points
    May 13, 2019 @ 21:58
    Jay Crowe
    0

    Nested Content as Macro Parameter

    Hi,

    I have created a parameter type for nested content data types and it seems to be working fine. I am then struggling to actually get at the data from the nested content.

    I can get nested content like: var images = Model.MacroParameters["Images"];

    But I am then struggling to loop round each one and display the data.

    Has anyone done this before?

    Any help would be appreciated.

    Cheers, Jay

    This is the data I get: [{"key":"0c189c8d-7d34-4996-88c4-0a7feb61851c","name":"Item 1","ncContentTypeAlias":"imageComposition","imageTitle":"Cumbrialife Food & Drink Awards","imageText":"Drinks producer of the year - finalist","image":"umb://media/af31ed4755da4948bde1f4aa1a949546"},{"key":"8066dfde-f97f-4412-9b1f-e022ddc4275e","name":"Item 2","ncContentTypeAlias":"imageComposition","imageTitle":"TEST","imageText":"TEST","image":"umb://media/af31ed4755da4948bde1f4aa1a949546"}]

  • Bojan 16 posts 131 karma points
    Jun 05, 2019 @ 19:35
    Bojan
    100

    I had the same situation.

    Once I enabled Nested Content for use in Macro parameter type (using https://github.com/skttl/ParameterEditorGenerator), I couldn't use Model.GetParameterValue<IEnumerable<IPublishedContent>>("paramAlias") as it will always return null. This method doesn't support nonstandard macro data types like Nested Content.

    I had to manually convert data sourse (JSON) using JsonConvert:

    var accordionItemsSource = Model.MacroParameters["accordionItems"] as string;
    var accordionItems = JsonConvert.DeserializeObject<List<dynamic>>(accordionItemsSource);
    

    NestedContentPropertyValueConverters doesn't work here automatically, but I guess it works only with published content.

    Here I found these embedded property converters that maybe can be used for conversion to IPublishedContent or IEnumerable

  • Jay Crowe 42 posts 173 karma points
    Jun 07, 2019 @ 06:47
    Jay Crowe
    0

    Hi Bojan,

    Thank you for your reply. That's exactly what I ended up doing was converting the json to a model I could use.

    Thank you for letting me know about the property converters. They look really useful so will have to give them a go.

    Cheers, Jay

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies