Copied to clipboard

Flag this post as spam?

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


  • Elin 45 posts 166 karma points
    Oct 23, 2017 @ 20:07
    Elin
    1

    How To Render Grid Layout in Nested Content

    Hi,

    I'm trying to render my grid which is located inside the nested content (see image below)

    enter image description here I usually use the code below to render my text from the nested content, but it's not working with the grid.

    @Umbraco.Field(item, “nestedGrid”)
    

    I also tried a few other codes that I could think of but nothing seems to be working.

    Thanks in advance for you help.

  • Laurence Gillian 600 posts 1219 karma points
    Oct 26, 2017 @ 08:38
    Laurence Gillian
    104

    I am doing the following:

    1. Get the property with Nested Content
    2. Pass it into a partial
    3. Render Grid

    View

    @Html.Partial("Components/ContentTabs", Model.ContentTabs)

    Partial

    @model IEnumerable<IPublishedContent>
    @if (Model.Any()) 
    {
    <div>
        @* List each piece of nested content *@
        <ul>
            @{
                var i = 0;
                foreach (var node in Model)
                {
                    i++;
                    <li>@i</li>
                    @* you can get your properties here too *@
                }
            }
        </ul>
    </div>
    <div>
        @* Render the Grid on each piece of Content *@
        @{
            var c = 0;
            foreach (var node in Model)
            {
                c++;
                @Html.GetGridHtml(node.GetProperty("contentGrid"))
            }
        }
    </div>
    }
    

    However, you could probably just do (untested)

    @{
        var nestedContent = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("contentTabs");
    
        foreach (var item in nestedContent)
        {
            @Html.GetGridHtml(item.GetProperty("contentGrid"));
        }
    }
    
  • Elin 45 posts 166 karma points
    Oct 26, 2017 @ 16:05
    Elin
    1

    Hi Laurence,

    I tried your untested snippet, and it worked beautifully.

    Thanks for helping with this.

Please Sign in or register to post replies

Write your reply to:

Draft