3

I am struggling with a very simple Umbraco 7 navigation. Basically, I have several "sites" in one solution – or, same site, but for different countries and languages. Their home page are top level nodes, and all the subpages are nested in level 2 and below.

This works fine for the individual sites (outputting the children of the level 1 node). However, I want to create a second menu which outputs only the top level nodes, where I can switch between the different sites. This, for some reason, I can't do.

@inherits UmbracoTemplatePage
@{
  var homePage = CurrentPage.AncestorsOrSelf(1).First();
  var subItems = homePage.Children;

  var rootItems = homePage.Siblings;
}

<ul>
  @foreach (var item in subItems) {
  <li>@item.Name</li>
  }
</ul>

<ul>
  @foreach (var item in rootItems) {
  <li>@item.Name</li>
  }
</ul>

It outputs the first list perfectly, but the second list has no output. If I try to output @homePage.Name it does give me an output, so I know the root items are accessible.

Ideally, I want it to output all the root nodes in the second navigation (basically SiblinbsOrSelf()).

What am I doing wrong?

Nix
  • 5,746
  • 4
  • 30
  • 51

1 Answers1

8

To get all nodes at the root level:

var rootNodes = Umbraco.TypedContentAtRoot();

This will include the current page, which can be omitted if necessary.

To output it in a ul as required:

<ul>
    @foreach (var n in rootNodes)
    {
        <li>
            @n.Name
        </li>
    }
</ul>
Nix
  • 5,746
  • 4
  • 30
  • 51
LoveFortyDown
  • 1,011
  • 2
  • 17
  • 37