DEV Community

Cover image for Simple Navigation Macro for Umbraco
Adam K Dean
Adam K Dean

Posted on

3 1

Simple Navigation Macro for Umbraco

I have started working with Umbraco, so a lot of my posts are probably going to be about that for the next few months at least.

This snippet is probably common knowledge for a lot of Umbraco developers, but for me, I had to look on the internet for almost 30 seconds to find it, so to make it easier for me to find it in the future, I'm posting it here. You're welcome future me.

<ul>
    @{ 
        var homeNode = Model.AncestorOrSelf("Home"); 
        var homeClass = Library.If(homeNode.Id == Model.Id, "selected", "");
    }

    <li><a href="@homeNode.Url" class="@homeClass">@homeNode.Name</a></li>      

    @foreach(var pageNode in homeNode.Children.Where("Visible"))
    {
        var pageClass = Library.If(pageNode.Id == Model.Id, "selected", "");

        <li><a href="@pageNode.Url" class="@pageClass">@pageNode.Name</a></li>
    }
</ul>
Enter fullscreen mode Exit fullscreen mode

No nesting support but easily addable, see here.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more