We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5689
    • 289 Posts
    I have two menus on a site I’m working on. One contains all main menu items, or top level documents. Some of these have child documents, and some don’t. My other menu contains these child documents if they exist. What I want to do is use a certain template for the main menu items that are active. It works if the top level document has no children using &hereTpl. However, when I have a parent document that is active in the menu, but whose child is the current document, I can’t get the same template to apply. I’ve tried &activeParentRowTpl, which should do what I want, but it’s not working. Here’s my complete Wayfinder call.

    [!Wayfinder? &startId=`0` &level=`1` &hereClass=`this` &outerTpl=`NavigationList` &rowTpl=`NavigationListItem` &hereTpl=`NavigationListItemThis` &activeParentRowTpl=`NavigationListItemThis` !]


    Am I missing something? Thanks. laugh
      I'm learning more about MODx all the time and loving it.
      • 16183
      • 1,390 Posts
      Hmm, strange...that should work. For example assuming the following menu hierarchy:

      Home
      About us
          Our history
          Our mission.

      If the either the document "Our history" or "Our mission" is currently selected in the menu then if you are using activeParentRowTpl, it should be applied to the document "About us". Is this your scenario (though not working)?

      cheers/k
        • 5689
        • 289 Posts
        Thanks for the quick reply. smiley

        I should have specified a little more about my menus. At the top of the site, there is a menu with links like Home, About Us, Contact Us, etc. That is my main menu. In a different part of the site, I have a menu that shows only the children of the current main menu item. So, for example, if About Us is the main section of the site the user is viewing, the submenu might have links like Who We Are, Our Mission, etc. These submenu items are children of the main menu items, but they show up in a completely different menu with a separate Wayfinder call.

        So if I go to a page like Who We Are, the About Us link in the main menu needs to get the template. However, it is just being treated like it is not an active parent. It’s possible this isn’t working right because of the way I’m doing my menus, where the children are not shown in the main menu but in their own, but I would think it should still work the same way.
          I'm learning more about MODx all the time and loving it.
          • 16183
          • 1,390 Posts
          No I don’t think it will work in that setup since they are being treated as separate menus. In my testings it worked if they were all part of the same menu.

          So you want the active child and its parent to have different classes? Why not use two different &hereClass? ....one for your submenu and the other for the main menu? You can achieve what you want without resorting to templates. By the way, you did not post the Wayfinder call for your second menu. Are you using UltimateParent for that? If you are then you can do it like this:

          First/main menu
          [[Wayfinder? &startId=`0` &outerTpl=`menuContainer` &rowTpl=`menuRows`  &level=`1`]]
          


          In the first menu above, the default &hereClass=`active` will be applied

          Submenu
          [!Wayfinder? &startId=`[[UltimateParent]]` &outerTpl=`menuContainer` &rowTpl=`menuRows` &level=`1` &hereClass=`subactive`!]


          Here the &hereClass=`subactive` will be applied. You can obviously give the parameters different values/names other than those in my example.

          The rest is a CSS affair..

          /k
            • 5689
            • 289 Posts
            I am indeed using UltimateParent. Let me post all of my chunks here.

            Navigation Menu
            <div id="navigation" class="clear">
            	[!Wayfinder? &startId=`0` &level=`1` &hereClass=`this` &outerTpl=`NavigationList` &rowTpl=`NavigationListItem` &hereTpl=`NavigationListItemThis` &activeParentRowTpl=`NavigationListItemThis` !]
            </div>


            Outer Template for Navigation (I’m not using lists - just floated a tags with display:block)
            [+wf.wrapper+]


            Row Template for Navigation
            <a [+wf.classes+] href="[+wf.link+]" title="[+wf.title+]" [+wf.attributes+]>[+wf.linktext+]</a>[+wf.wrapper+]


            Here Template (active menu item - I don’t want it to be a link at all but just text)
            <span [+wf.classes+]>[+wf.linktext+]</span>[+wf.wrapper+]


            Subnavigation Menu (uses templates from main menu)
            <div id="subnavigation" class="clear">
            	[!Wayfinder? &startId=`[[UltimateParent]]` &hereClass=`this` &level=`1`  &outerTpl=`NavigationList` &rowTpl=`NavigationListItem`!]
            </div>


            Note that at this point I’m not concerned with making the second menu’s (subnavigation) active item work because I should have no problems with that. I’m mainly concerned with the main menu right now.

            It seems to me that even though they are separate menus, Wayfinder should still be able to recognize when a main menu item is the parent of an active child and apply the template accordingly, but maybe that’s just not how it works.
              I&#39;m learning more about MODx all the time and loving it.
              • 5689
              • 289 Posts
              kongondo, I cannot use classes because I am using span tags in place of a tags for active links. I figure if the menu item is active, I don’t want it to be a link. CSS classes cannot achieve this.

              I tried using a snippet with UltimateParent to determine if an item is a parent of an active child, but that kept brining in too many problems. I then decided to delve into the Wayfinder code and see what I could figure out. I am pleased to say I have been successful! laugh

              I have Wayfinder 2.0. If you look in the wayfinder.inc.php file on line 157, you will find the following code:
              } elseif ($resource['isfolder'] && $this->_templates['activeParentRowTpl'] && ($resource['level'] < $this->_config['level'] || $this->_config['level'] == 0) && $this->isHere($resource['id'])) {

              This is part of an if...then...else statement that determines what template to apply to a row. Notice specifically the part of this line that says:
              ($resource['level'] < $this->_config['level'] || $this->_config['level'] == 0)

              This checks to see if the row in question has a lower level (0 being the lowest level, so higher up in the hierarchy) than the level specified in the parameter for the Wayfinder call. I specified a level of 1 to only show the top level links. So none of these top level links will ever pass this elseif statement and get the activeParentRowTpl template. I’m not quite sure why the author did this, but changing the < to <= or simply removing the entire part that checks the level makes my menu work exactly like I want.

              I will investigate further why the author might have written this code this way and whether the level checking would be necessary in some situations. I may end up modifying Wayfinder to add another parameter that lets me override this level checking for activeParentRowTpl. I’ll post again with details when I come up with something. For now, though, the modified code is working well. laugh
                I&#39;m learning more about MODx all the time and loving it.
                • 25663 MODX Staff
                • 12,272 Posts
                Quote from: Compeek at Jun 05, 2009, 06:48 PM

                kongondo, I cannot use classes because I am using span tags in place of a tags for active links. I figure if the menu item is active, I don’t want it to be a link. CSS classes cannot achieve this.

                I’m utterly confused by this statement. Classes have nothing to do with link behavior; they’re simply part of the cascade and can be used as selectors. You could create separate rowTpls and hereTpls. I can promise you kongondo knows a thing or two about wayfinder and has great suggestions. wink
                  Ryan Thrash, MODX Co-Founder
                  Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                  • 5689
                  • 289 Posts
                  I’m sure he knows a lot, but I don’t think you quite understand what I’m saying. smiley

                  I’m not worried about the second menu right now. I’m just focusing on the main menu. This is what I’m trying to do. Let’s say I have two main menu items. One is Home, and the second is About Us. Home has no children. About Us has two children, Mission and Location. I am using Ultimate Parent with About Us so it automatically goes to Mission. Now, I always want the active main menu item to have a certain template, NavigationListItemThis. This code for Wayfinder call for the main menu makes Home have this template when Home is the current page:
                  &hereTpl=`NavigationListItemThis`

                  However, let’s say I go to the Location page. Now Location is the current page, but About Us is the active main menu item. I want About Us to get the NavigationListItemThis template. The previous code obviously won’t take care of that because About Us is not the current page, but one of it’s children are. So to achieve the same result, I attempt to use this code:
                  &activeParentRowTpl=`NavigationListItemThis`

                  About Us is the activate parent, but it is not the current page itself, so this could presumably would assign the template. However, it’s not.

                  After looking at Wayfinder’s PHP code like I described in my last post, I figured out that the reason activeParentRowTpl isn’t working is because the level of the About Us page (1) is not less than the level I specified in my Wayfinder call (1); they are equal. The Wayfinder elseif statement only evaluates as true is the level is less than the level parameter. I assume this is to prevent the bottommost child in a menu from receiving the template from activeParentRowTpl, but in my case all of the menu items are both the parent and the bottommost child because I only have one level of menu items, so the About Us item is not getting the template specified with activeParentRowTpl. Modifying the Wayfinder code makes this work, but obviously that’s not an optimal way to fix the problem because there will be other cases where I don’t want that to happen as it is sort of an exception to the normal behavior of Wayfinder. Understand what I mean?

                  I’m not saying kongondo is wrong, but he misunderstood what I was trying to do. He suggested using &hereClass differently for each menu, but &hereClass has nothing to do with what I’m trying to accomplish. And the reason I said I can’t use a class for the active menu item is because if you look at my template chunks for the active item, I am using span tags to show the text, whereas the rest of the menu items that are not active are links with the a tag. If I was to simply use a class to specify the active item, it would still be a link. I do not want my active items to be links; I want them to be plan text wrapped in span tags.

                  I hope this has made my situation more clear. I’m not trying to do anything with the submenu at this point; I’m trying to get the active main menu items to get the right template when one of their children is active, even though the children are on a completely separate menu with a separate Wayfinder call. smiley
                    I&#39;m learning more about MODx all the time and loving it.
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    &selfClass - The CSS class name specified in this parameter will appear in the [+wf.classes+] and [+wf.classnames+] placeholders of the row corresponding to the current document. Thus it can only appear once in any instance of Wayfinder output.
                    &hereClass - The CSS class name specified in this parameter will appear in the [+wf.classes+] and [+wf.classnames+] placeholders of the row(s) corresponding to: the current document, and its parent, and its grandparent, etc. all way up to the level just below the starting document. This allows you to apply a distinctive set of style rules to the chain of documents that leads from the top of the menu structure down to the current document -- no matter how many levels deep it might be. Note that these are the same documents that would be listed in a breadcrumb trail.
                      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
                      • 5689
                      • 289 Posts
                      I really appreciate your guys’ help, but I’m trying to tell you that I can’t use class parameters. They need to be templates. tongue

                      My activate one will always use <span></span> while the rest will use <a></a>. I need separate templates to accomplish this! smiley
                        I&#39;m learning more about MODx all the time and loving it.