I knew there had to be a simple, efficient, and effective way to build nested menus using getResources instead of Wayfinder, and I finally figured out a way. With this discovery, I’ll likely never use Wayfinder again.

Creating nested menus using only getResources is now very easy to do. The introduction of the tplWrapper property in the 1.6.0 release provided the gift wrapping. Now let’s unwrap it and see how we can use this present.

Limiting the Depth of Your Nesting

I have successfully created some simple nested calls to build a menu tree. But in the past, I have either been limited to infinite depth, or been forced to define a different tpl for each specific level of the menu by redefining it for each nested getResources call. But recently, I discovered a gracefully simple way to achieve a nested menu to a specified depth with getResources.

All you need to do is define a custom property. Let’s call ours level.

[[getResources@nav? &parents=`[[*id]]` &level=`1`]]

Then you define your tpl using an output filter which increments this custom property value for use in each nested call.

<li><a href="[[~[[+id]]]]">[[+menutitle:default=`[[+pagetitle]]`]]</a>
[[[[+level:lt=`2`:then=`getResources@nav? &parents=`[[+id]]` &level=`[[+level:add]]``:else=`-`]]]]</li>

That’s it! A fully nested navigation menu. Without Wayfinder. Without a different tpl per level.