Copied to clipboard

Flag this post as spam?

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


  • Matt 353 posts 825 karma points
    Oct 15, 2019 @ 09:36
    Matt
    0

    Get a list of sub pages within a folder page node

    Hi,

    So I'm working on a section which is basically going to list a load of departments, inside of those will have a number of sub pages.

    Here is my tree;

    enter image description here

    So I made a doc type called "BlankFolder" with no template which created my "Departments" node folder

    Then I created a "Department" node with a template which is the main departments page.

    Inside the Department page I want to list all of the sub pages e.g About the team, support and advice etc on the Department Template.

    I got this work for the "Breast Department by using the query builder. but what I dont want to do is keep having to create it manually. So e.g if I created Plastic Surgery as a department and added some sub pages under it all the sub pages under that would automatically get generated.

          @{
              var selection = Umbraco.Content(Guid.Parse("e29e2b35-b2e7-4c08-a3b9-18923f79bc2b"))
              .ChildrenOfType("generalTemplate")
              .Where(x => x.IsVisible());
          }
          <div class="columns-6 w-row">
              @foreach (var item in selection)
              {
                  <div class="w-col w-col-3">
                      <a href="@item.Url" class="blue-box-test w-inline-block">
                          <h3 class="box-title">@item.Name</h3>
    
                      </a>
                  </div>
              }
          </div>
    

    The above code works for breast department, but how can I tweak it to automatically work for other departments created?

    Thanks in advance

  • Mike Chambers 635 posts 1252 karma points c-trib
    Oct 15, 2019 @ 11:41
    Mike Chambers
    0

    var selection = Umbraco.Content(Guid.Parse("e29e2b35-b2e7-4c08-a3b9-18923f79bc2b"))

    does that not just become Model? eg the page that I'm currently on (being a department page)

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Oct 15, 2019 @ 12:29
    Steve Morgan
    1

    You're nearly there with your logic.

    Remember there is context of what page you're on at the moment.. so you need to say on this "department" page - I want all the children below rather than hardcoding a specific department.

    Model is your friend here - it will be the page you're on;

        Model.ChildrenOfType("generalTemplate")
          .Where(x => x.IsVisible());
    

    If you need to list these child pages from a page other than a department page then you need to find the department first by traversing up or down the tree to find it (look at AncestorOrSelf and the various related methods to help you from the Model page.

    HTH

    Steve

  • Matt 353 posts 825 karma points
    Oct 15, 2019 @ 12:56
    Matt
    0

    Thanks guys, great help :)

Please Sign in or register to post replies

Write your reply to:

Draft