Copied to clipboard

Flag this post as spam?

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


  • Ric Carey 47 posts 89 karma points
    May 01, 2020 @ 14:58
    Ric Carey
    0

    Get IEnumerable<IPublishedElement> from Nested Content Database Value

    Hey,

    I am messing around with some properties via the save event/content service in a V8 Component. And would like to access some data I have saved as a Nested Content datatype. Is there a way with IContent to access Nested Content data from within a converted object?

    e.g. Deserialize the Nested Content Json to IEnumerable

    I can't use the Umbraco Helper as the cache doesn't appear to have been updated at this point. (ContentService.Saved or ContentService.Saving) So to do it that way would require the editor to click publish twice.

    I've tried, but this doesn't work:

      var text = content.GetValue<string>("layoutContent");
     JsonConvert.DeserializeObject<List<PublishedElement>>(text) 
    

    Cheers Ric

  • Ric Carey 47 posts 89 karma points
    May 01, 2020 @ 15:42
    Ric Carey
    0

    (for anyone who stumbles across this) I've achieved what i wanted to using

     JsonConvert.DeserializeObject<List<dynamic>>(text) 
    

    And then a series of null checks and subsequent deserialisation for nested nested. Works, but feels very v4 like.

  • Carlos Casalicchio 117 posts 479 karma points
    Nov 28, 2020 @ 02:35
    Carlos Casalicchio
    0

    I am having a hard time with this, because in v7 one could simply call

    content.Value<IEnumerable<IPublishedElement>>(propertyAlias)
    

    and it would work. Now, I'm having to use a very cumbersome List<dynamic> for everything.

    Is it possible to access IEnumerable<IPublishedElement> from within a IContent object? Using the IContentService.GetById method?

    This is becoming annoying really fast.

  • Malthe Petersen 67 posts 361 karma points c-trib
    Nov 28, 2020 @ 08:06
    Malthe Petersen
    1

    Hi Carlos.

    You cannot access any published content within the IContent.

    What I would suggest is that you listen to the ContentCache.CacheUpdated, because now you can access the IPublishedContent and use it as you normally would.

    Hope it helps.

  • Carlos Casalicchio 117 posts 479 karma points
    Nov 28, 2020 @ 23:29
    Carlos Casalicchio
    0

    Perfect, that works! Thank you!

  • 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