Menus

Menu Item Opens Its First Child

light fare

First Child Redirect

Sometimes you don't have content for a top-level menu item, and you want a click on it to open its first child instead. In mid-2006 Jason Coward (opengeek) released the FirstChildRedirect snippet to do just that.

mmcgee asked...

I have one main container, containing two menu items. I don't really have content yet for a landing page yet for the top level item. Eventually there will be many other drop menus in this category – too many to fit all in the top level menu.

properties
—featured
—sold

I have content for featured and sold, but not necessarily for properties. What's the best approach for making the click on properties direct the featured page? Can I create a blank template with a php redirect? Is there something I can set in the resource manager for the properties resource.

Had same question on the forum some time ago, but at the time it seemed easier and faster to just create a page of filler content.

The Solution:

sottwell says...

There is a FirstChildRedirect snippet that you can use on the content of your container page.

http://rtfm.modx.com/extras/revo/firstchildredirect

What's the Story?

This is a very common requirement. Way back in mid-2006 Jason Coward (opengeek) released the first version of FirstChildRedirect. It's a very short snippet, all it does is get the first child of a given resource (the current one, the one the user clicked on in the menu by default) and redirect the user. 

Since then, it's been modified and updated to offer more options and take advantage of the core functionality of Revolution. But after all the processing of the options, it still just makes a URL out of the resource ID of the desired resource using makeURL() and uses that in the sendRedirect() API function. The user clicks on a link item, and gets redirected to its child.

Here's the official documentation http://rtfm.modx.com/display/ADDON/FirstChildRedirect