Copied to clipboard

Flag this post as spam?

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


  • Michael Beever 74 posts 155 karma points
    Oct 14, 2020 @ 10:47
    Michael Beever
    0

    Umbraco 8 Upgrade CurrentPage.Children

    Hello,

    I am upgrading from 7 to 8 and in my code i was using CurrentPage.Children to pull through all of the pages.

    In 8 this method does not work and I am unable to find a way to replicate this in 8.

        @{
            var selection = CurrentPage.Children;
    
            string YearURL = Request.QueryString["Year"];
    
        }
    
        <div class="row">
    
            @foreach(var item in selection)
            {
    
    
            if (@item.FilterYear == @YearURL || @YearURL == "All")
            {
    
    
            <div class="col-sm-6" style="padding-bottom:20px;">
    
                <a href="@item.Url?Year=@YearURL"><div class="card text-center">
                  <div class="card-header">
                    <h6>@item.Name</h6>
                  </div>
                  <div class="card-body1">
                    <h5 class="card-title"></h5>
                    <p class="card-text">Read the Meeting minutes here</p>
                    </div>
    
                </div></a>
    
            </div>
    
            }
    
  • Marc Goodson 2157 posts 14435 karma points MVP 9x c-trib
    Oct 14, 2020 @ 13:41
    Marc Goodson
    0

    Hi Michael

    'CurrentPage' has been removed in V8, so I think you are after

    var selection = Model.Children;
    

    or

    var selection = Model.Children(f=>f.IsVisible());
    

    If you want to filter out any children that have 'umbracoNaviHide' property ticked.

    There is also now an overload for culture, if you are building a multi-culture site with variants.

    And if you are in a PartialView where perhaps you have changed the underlying Model, then you can still access the current published page via the UmbracoContext eg:

     var children = UmbracoContext.PublishedRequest.PublishedContent.Children();
    

    regards

    Marc

  • 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