Copied to clipboard

Flag this post as spam?

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


  • Callum Douglas 9 posts 111 karma points
    Oct 12, 2016 @ 13:28
    Callum Douglas
    1

    Why isn't CurrentPage.Children returning the children?

    Code I'm using shown below, something's wrong.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
        @{
            Layout = "Master.cshtml";
        }
    
        <div id="main-content" class="container">
    
            <div class="col-xs-12">
    
                @foreach(var post in CurrentPage.Children)
                {
                    <div class="col-xs-12">
    
                        <a href="@post.Url">
    
                            <h4 class="col-sm-7 col-xs-12">@post.Name</h4>
    
                            <img class="col-sm-5 col-xs-12" src="" />
    
                        </a>
    
                    </div>
                }
    
                <h1>@CurrentPage.Name</h1>
    
            </div>
    
            <div class="clearfix"></div>
    
        </div>
    

    So that's my code above, I have a Portfolio landing page which has children in a list view which are portfolio items.

    So it's in a blog format. But I can't seem to get these children for whatever reason.

    What am I doing wrong?

    Thanks in advance

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Oct 12, 2016 @ 13:56
    Dennis Adolfi
    100

    Hi Callum.

    Your code should be working, if your Portfolio items are published. Can you make sure that all the portfolio items are published? Right click on your portfolio node and select Publish, and tick both checkboxes saying "Publish ... and all its subpages" and "Include unpublished child pages".

    I copied your code and pasted into an existing project and that works fine. Here is your code but stronly typed:

    <div id="main-content" class="container">
        <div class="col-xs-12">
            @foreach (var post in Model.Content.Children)
            {
                <div class="col-xs-12">
                    <a href="@post.Url">
                        <h4 class="col-sm-7 col-xs-12">@post.Name</h4>
                        <img class="col-sm-5 col-xs-12" src="" />
                    </a>
                </div>
            }
    
            <h1>@Model.Content.Name</h1>
        </div>
        <div class="clearfix"></div>
    </div>
    

    If it still does´nt work, I can take a look at it if you want, if you have a dev enviroment.

    Take care / Dennis

  • Callum Douglas 9 posts 111 karma points
    Oct 12, 2016 @ 14:21
    Callum Douglas
    1

    I'm an idiot!! They weren't published, works fine now.

    Thanks Dennis!

    Also while you're here...

    Should I be using Strongly Typed instead of Dynamic?

    I have heard it's better but I personally have found Dynamic much easier to use.

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Oct 12, 2016 @ 14:29
    Dennis Adolfi
    0

    Glad i could help Callum. Those things happens! :)

    Personally I prefer Strongly Typed, especially with Visual Studio and intellicense. But if you are new to Umbraco and you feel comfortable with Dynamic, then I dont want to be the "dont-do"-guy. :)

    I really recommend reading this article by Dave Woestenborghs about Stronly typed vs. Dynamic: http://24days.in/umbraco/2015/strongly-typed-vs-dynamic-content-access/

    Read it, and then choose whatever approach that feels best for you.

    Have a great day!

Please Sign in or register to post replies

Write your reply to:

Draft