We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37272
    • 216 Posts
    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.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I did the same thing by using the &displayStart parameter and jiggling the startItemTpl and the outerTpl to get everything into the same <ul> tags. The startItemTpl had the beginning <ul> tag as well as its own <li> tags, including the [+wf.classes+] placeholders, and the wf.wrapper placeholder. The outerTpl just had the wf.wrapper and the closing </ul> tag.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 37272
        • 216 Posts
        Hi Susan,

        When I tried using the &displayStart paramter, I couldn’t get the active class to work properly. If the active class is not required, then using the &displayStart might be the easier option. Unless of course, there is way to get the active class to work properly with the &display Start parameter! Is there?

        Just to make my opening post a little clearer, the two first Wayfinder calls use the parameter and value, ’&outerTpl=`sub-menu-open`’. Either Wayfinder call (remember, they are mutually exclusive - only one of them will be called) will open the div. The ’sub-menu-open’ template contains:

        <div class="sub-menu">
        <ul>[+wf.wrapper+]


        The third Wayfinder call and value, ’&outerTpl=`sub-menu-close`’ is always called, and closes the div with:

        [+wf.wrapper+]</ul>
        </div>


        The default templates do the rest.

        It is as simple as that.