Copied to clipboard

Flag this post as spam?

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


  • k 255 posts 652 karma points
    Apr 23, 2018 @ 11:51
    k
    0

    Nested content

    Hello,

    I am using nested content and it works fine when I use the below :

    var items = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("myPropertyAlias");
    
    foreach(var item in items)
    {
        // Render your content, e.g. item.GetPropertyValue<string>("heading")
    }
    

    However when I try to get the values of a child node as below :

      foreach(var cat in CurrentPage.Children.Where("Visible"))
            {
                var items = cat.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("director");
                foreach(var item in items)
                    {
    
                        <h3>@item.GetPropertyValue("test")</h3>
    
                    }
            }
    

    I get nothing from "cat"

    Can someone please help me with the right syntax ? Please help me find what I am doing wrong.

    Thanks,

    Kusum

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Apr 23, 2018 @ 12:15
    Alex Skrypnyk
    0

    Hi

    Use this code:

    foreach(var cat in Umbraco.AssignedContentItem.Children.Where(x => x.IsVisible()))
    {
        var items = cat.GetPropertyValue<IEnumerable<IPublishedContent>>("director");
        foreach(var item in items)
        {
    
            <h3>@item.GetPropertyValue("test")</h3>
    
        }
    }
    
  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Apr 24, 2018 @ 10:48
    Alex Skrypnyk
    0

    Hi K

    Did you solve the issue? Share with us, please.

    Thanks,

    Alex

  • k 255 posts 652 karma points
    Apr 24, 2018 @ 13:26
    k
    0

    Hello Alex,

    Sorry for late reply.

    I have used the above code but I am getting the below error ; enter image description here

  • Steve Morgan 1278 posts 4216 karma points c-trib
    Apr 24, 2018 @ 15:23
    Steve Morgan
    100

    Hmmm.. you shouldn't need to null check but does this work?`

        @foreach(var cat in Model.Content.Children().Where(x => !x.GetPropertyValue<bool>("umbracoNaviHide")))
    {
        if (cat.HasValue("director"))
        {
            var items = cat.GetPropertyValue<IEnumerable<IPublishedContent>>("director");
            foreach (var item in items)
            {
    
                <h3>@(item.GetPropertyValue<string>("test"))</h3>
    
            }
        }
    }
    
  • k 255 posts 652 karma points
    Apr 26, 2018 @ 07:14
    k
    0

    Hi steven,

    Thanks a lot. Code working perfectly well. :)

    k

  • 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