Copied to clipboard

Flag this post as spam?

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


  • Natalie 22 posts 162 karma points
    Jun 11, 2019 @ 09:50
    Natalie
    0

    Get children Item from the proper content page

    Hi !

    I am trying to get the chidren result of a parent : Her are my two pages and their children

    But I just have the content of the first page "Formation Example" rendered in my view

    The Child "Test" in there

    Is also there :

    I would like to know if is there is a way to render the proper Items in the second page.

    Here is how it is done :

        @{
        var selection = CurrentPage.Children(CurrentPage.Id)
                                .Where(x => x.IsVisible());
        }
    
        <ul>
            @foreach(var item in selection){
                <li>
                    <a href="@item.Url">@item.Name</a>
                </li>
            }
        </ul>
    

    If you have an idea to help me to go further.

    Thanks

  • Natalie 22 posts 162 karma points
    Jun 11, 2019 @ 14:38
    Natalie
    100

    I found out ! :)

    @{ 
        IPublishedContent homePage = Umbraco.AssignedContentItem.AncestorOrSelf("page");
        IEnumerable<IPublishedContent> pageLinks = homePage.Children();
    }
    
    <ul class="link-page-formation">
        @if (pageLinks != null && pageLinks.Count() > 0)
        {
            foreach (IPublishedContent page in pageLinks)
            {
                <li><h6><a href="@page.Url">@page.Name</a></h6></li>
            }
        }
    </ul>
    

  • sercansayin 1 post 21 karma points
    Mar 16, 2022 @ 13:14
    sercansayin
    0

    it worked for me, thanks.

Please Sign in or register to post replies

Write your reply to:

Draft