At Imulus we’ve been interactively trying Umbraco 5 off and on for the past 8 months or so. As of this last week we finally took the dive to do our first full-fledge project with version 5.01.

Now, there’s a lot of discussion to be had over whether or not Umbraco 5 is ready for prime-time, the lack of documentation, speed, and bugs give us hesitance about using it for larger projects. That said, it’s clearly the future and we are excited to see it evolve.

One of the initial challenges with any CMS is determining the best way to spit out a list of pages. Rather it’s for navigation, or a site map, you need a way to generate page lists. In Umbraco 4 we used a XSLT Macro that we slowly built and refined over several years, this allowed for a huge variety of navigation support.

With our recent dive into Umbraco 5 it makes sense to rebuild the base of this functionality using Razor. The initial goal: build a one-level navigation that spits out children of the current page, or — if specified, a target page.

The first thing to do is create a new macro and link it to a macro partial file. As always you can do this from the Developer section. Once that’s done add a parameter of “pageAlias” to the Macro and allow it to be input as a textstring. At this point you’ll also need a global document type property called “pageAlias”, this way we can target specific pages in the system without hardcoding a Document Type Alias or Source ID. Both of which aren’t as reusable as we want.

Insert the Macro call into a view as follows:

Specify pageAlias if you want to target a set page, otherwise it will just output the current children.

Now, let’s look at the macro code to generate the list, it’s heavily commented so you can follow:

Hopefully the above code is fairly easy to follow. It will output a group of LI’s one-level deep from the parent, each of these LI’s will show as the first in the list, last in the list, or currently active page.

Next Steps:

  • Allow for multi-level support via a parameter (i.e. show only 3 levels)
  • Make sure if you’re on a page underneath the active page that ‘active’ still shows.
  • Allow for a limit on the amount of pages to be displayed (i.e. show top 3)