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.

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more