A while ago, I had a problem generating a sub-menu that included the containing document, and I’ve now noticed a couple of other threads on this subject. I was trying to generate a menu that treated the containing document and children as tough they were all on the same level, and correctly attributed the active class. I found the solution was to make two mutually exclusive calls to generate the menu.
Some previous threads on this subject:
http://modxcms.com/forums/index.php/topic,36261.0.html
http://modxcms.com/forums/index.php/topic,37050.0.html
And perhaps this thread (if I understand the situation correctly):
http://modxcms.com/forums/index.php/topic,36463.0.html
This also might be an alternative to the FirstChildRedirect snippet, which I’ve sometimes seen suggested in these kind of situations. After all, it is good SEO to limit the number of levels to a website, and not needlessly waste a parent document by redirecting to a child document.
I added the code a couple of months ago, and there was lot of hit and miss involved, so I am now unable to provide a full answer of how this works - hopefully someone else will be able clarify any questions.
The main menu Wayfinder call:
[[Wayfinder? &hereClass=`active` &startId=`0` &level=`1` &textOfLinks=`pagetitle` &outerTpl=`webpage-menu`]]
The sub-menu Wayfinder calls:
[!Wayfinder? &startId=`0` &includeDocs=`[[UltimateParent?]]` &excludeDocs=`[*id*]` &activeParentRowTpl=`no-here` &outerTpl=`sub-menu-open`!]
[!Wayfinder? &startId=`0` &includeDocs=`[[UltimateParent?]] `&excludeDocs=`[*parent*],1` &level=`1` &activeParentRowTpl=`no-here` &outerTpl=`sub-menu-open`!]
[!Wayfinder? &startId=`[[UltimateParent?]]` &level=`1` &outerTpl=`sub-menu-close`!]
Depending upon if the page being viewed is the containg document or not, one of the first two calls are used to generate the first menu item (the containing document). These two calls include &outerTpl to ’open’ the html for the sub-menu block. The closing Wayfinder call includes the html to ’close’ the sub-menu block, and generates the rest of the menu.
The &excludeDocs perameter includes any main menu documents that contain no child documents. There’s probably a way for automating this, but I couldn’t achieve it.
I used the &textOfLinks=`pagetitle` perameter and value so that when the containing menu item appeared in the sub-menu, it could be titled ’introduction’ or other suitable and different title to the active main menu title.
It is possible that my Wayfinder calls could be rationalised, as I was trying out no end of combinations. If my description of the menu structure is unclear, send me a PM and I’ll send you a link to the site using this menu.
Edit: typos.