2013 April

MODx (Evo): Setting up a subnavigation – if there are subpages (children)

| development (web) | One Comment

Wayfinder is a great tool for MODx to automatically display menus and submenus on your website. By default though, it doesn’t handle not displaying the submenu on a subpage if there are no children, so you end up with the title of the page appearing where the menu should be.

So that you can just have one template for subpages, you can use a snippet to check if there are children for that page, and if so display the sub menu.

Here is the code I use.

1. Create a chunk called ‘subnav’

2. Create a snippet called ‘displaySubnav’
$chunkArr = array(); // if you want to parse stuff to the chunk, put it in an array here.
echo $modx->parseChunk('subnav', $chunkArr, '[+', '+]');

3. Call the snippet in your template – must be a non-cached call.

Now if there are children you’ll see a sub menu, and if there isn’t it will just appear blank.