Copied to clipboard

Flag this post as spam?

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


  • Dan 12 posts 91 karma points
    Sep 04, 2014 @ 14:52
    Dan
    0

    Show pages within section

    Hey,

    I'm working on a site that has a page structure similar to that below:

    - Home
    - Contracts
      -- Commercial
        --- Commercial Sub Page 1
        --- Commercial Sub Page 2
      -- Private
        --- Sub Page 1
        --- Sub Page 2

    (etc)

    The pages all have a standard template, but I'm wondering how I could use Razor to display all pages within a section. Say If I was on 'Commercial Sub Page 1' how could I show a list of other pages in the commercial section on the page?

    I'm using Umbraco 7

    Many thanks!

  • Steve Morgan 1350 posts 4460 karma points c-trib
    Sep 04, 2014 @ 16:54
    Steve Morgan
    100

    Are you saying you've got a single documen type or am I misreading thsi?

    It would be much nicer to go up to up to the parent "SectionDocType" - e.g. CurrentPage.AncestorOrSelf("SectionTypeAlias") but this should work via level:

    If you have to include this on all pages then you'll need to check what level you're on I guess (included - I've guessed level two).

    @{
        if(CurrentPage.Level > 2) {
        var section = CurrentPage.AncestorOrSelf(2);
        if (section != null)
        {
            var childItems = section.Children;
            foreach (var page in childItems)
            {
                <p>@page.Name</p>
            }
        }
        }
    }
  • 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.

    Continue discussion

Please Sign in or register to post replies