0
votes

I'm trying to create a razor menu in umbraco with a razor macro. I followed the umbraco tutorial about creating a razor menu:

http://umbraco.com/help-and-support/video-tutorials/umbraco-fundamentals/razor-recipes/navigation/TVPlayer

It works for my first three pages but then I want to add another one but the page doesn't show up in my menu. I have the following structure for my pages:

enter image description here

Start, calendar and Foto's do show up in my menu, but the news page doesn't. Is this structure correct or do I have to create a 'Home' page and place all my pages under that?

This is my razor macro code:

@inherits umbraco.MacroEngines.DynamicNodeContext
<nav>
<ul>
    @{ var homeNode = Model.AncestorOrSelf("Home"); }

    <li><a href="@homeNode.Url" class="@Library.If(homeNode.Id == Model.Id, "selected", "")">@homeNode.Name</a></li>

    @foreach (var page in homeNode.Children.Where("Visible"))
    {
        var isSelected = false;
        if (Model.Id == page.Id || (Model.Parent != null && Model.Parent.Id == page.Id && Model.NodeTypeAlias != "Textpage"))
        {
            isSelected = true;
        }

        <li>

            <a href="@page.Url" class="@Library.If(isSelected, "selected", "")">@page.Name</a>

            <!-- If the page has child nodes (2nd level) that are visible and docTypeAlias is Textpage (textpages) -->
            @if (page.Children.Where("Visible").Count() > 0)
            {
                <ul>
                    @foreach (var childPage in page.Children.Where("Visible"))
                    {
                        <li>
                            <a href="@childPage.Url" class="@Library.If(childPage.Id == Model.Id, "selected", "")">@childPage.Name</a>
                        </li>
                    }
                </ul>
            }
        </li>  
    }
</ul>
</nav>
1

1 Answers

1
votes

Ideally yes you need a page made with a doc type with the alias "Home" as you are defining you starting node/var by getting that page here,

var homeNode = Model.AncestorOrSelf("Home");

then after you are getting all the child pages of this homeNode so really all your structure should be

content
- Home
  - start
  - calender
  - frontpage sliders
  - fotos
  - news