Home
Atom Feed

Simple navigation macro for Umbraco 5

This is a simple macro for generating a single-level menu from a source. If you dont specify a source, it will use the current page as source.

Log in to your Umbraco 5 backend and go to the "Developer" section. Right click "Macro Partials", and click "Create".
Name your macro "Navigation".

Add the following macro parameters:

Then paste the following into the macro editor:

@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework

@{ var source = string.IsNullOrEmpty(Model.MacroParameters.Source) ? Model.CurrentPage.Id : Model.MacroParameters.Source; }

<ul>
@foreach(var child in Umbraco.GetDynamicContentById(source).Children) {
  if (child.umbracoNaviHide != null && !bool.Parse(child.umbracoNaviHide)) {
    var activeClass = (Model.CurrentPage.Id == child.Id ? "active" : "");
    <li><a href="@child.NiceUrl" class="@activeClass"><span>@child.Name</span></a></li>
  }
}
</ul>

Go to the "Navigation" node under "Macro" and navigate to the "Macro Parameters" tab.
Add a new parameter named "Source" of type "Content Picker".

Then just save the macro and add it to a template where you want the navigation to appear.