We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25803 ☆ A M B ☆
    • 721 Posts
    Hello,

    I’ve created the following Wayfinder call for the main menu of this site (harmony.adrenalineonline.net - still in development) and it works wonderfully:

    <div class="menu">[!Wayfinder?&level=`1`&config=`harmonymenu`&startId=`[*Parent*]!]</div>


    Note, I’m a little confused that the [*Parent*] element doesn’t work if I put a closing tick after it but that’s not a primary concern at the moment.

    The config file for reference:

    <?php
    
    	$firstClass = 'first';
    	$lastClass = 'last';
    	$hereTpl = '';
    	
    	$outerTpl = '@CODE:<ul>[+wf.wrapper+]</ul>';
    	
    	$rowTpl = '@CODE:<li [+wf.classes+]><a href="[+wf.link+]" title="[+wf.title+]"><strong>[+wf.linktext+]</strong><br /><span class="itemdescription">[+wf.introtext+]</span></a>[+wf.wrapper+]</li>';
    
    ?>


    Certain sections of the site will have submenus. For now I’m using one page to start building on, the Environment page (harmony.adrenalineonline.net/Environment).

    My objective is to have the submenu call in the master template. Currently I have this:

    <div class="submenu">[!Wayfinder?&level=`2`&config=`harmonysubmenu`&startID=`[*Parent*]!]</div>


    With the config file:

    <?php
    
    	$firstClass = '';
    	$lastClass = '';
    	$hereTpl = '';
    	
    	$outerTpl = '@CODE:<ul>[+wf.wrapper+]</ul>';
    	
    	$rowTpl = '@CODE:<li[+wf.classes+]><a href="[+wf.link+]" title="[+wf.title+]">[+wf.linktext+]</a>[+wf.wrapper+]</li>';
    
    ?>


    I haven’t styled the submenu yet (will do so after it gets working) but it does display on the environment page. It disappears, however, if you click on one of the pages in the submenu. I thought it might have something to do with the startId but this call:

    <div class="submenu">[!Wayfinder?&level=`2`&config=`harmonysubmenu`!]</div>


    Works the same way. I’m pretty confused and realize it’s probably something very simple.

    As for the tree, the pages that make up the items in the main menu are at the root level and the pages that make up the items for the submenus will be (and are in the Environment section) children of the relevant parent page.

    Can anyone point out what I’m doing wrong/why the submenu disappears on the children page?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      That’s [*parent*]; case is important.

      You can also use the UltimateParent snippet, which will return just what it suggests:
      [!Wayfinder? &startId=`[[UltimateParent]]` ... !]

      Note the differences in the outer and inner snippet calls.

        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
        • 25803 ☆ A M B ☆
        • 721 Posts
        Thanks for the note on [*parent*].

        This is the body part of the my template:

        <body id="[*alias*]">
        <div class="masthead">{{masthead}}</div>
        <div class="menu">[!Wayfinder?&level=`0`&hideSubMenus=`true`&config=`harmonymenu`&startId=`[*parent*]`!]</div>
        <div class="container">
        <div class="header">{{header-environment}}</div>
        <div class="submenu">[!Wayfinder? &startId=`[[UltimateParent]]`!]</div>
        <div class="content">[*#content*]</div>
        </div>
        <div class="footer">{{footerselect}}</div>
        </body>


        I’ve used [[UltimateParent]] in the submenu and it now stays displayed in the submenu area. Problem now is that the main menu also gets replaced by the items in the submenu and the submenu items show up in the main menu when you click the environment link. I obviously don’t understand the documentation for this snippet, or have a distorted understanding. I know I can hide the submenu in the main menu via CSS and I’m pretty sure that I’m seeing the main menu replaced by the submenu items when clicking a sub page because of the startID in the main menu snippet call, but when I use [[UltimateParent]] there, the entire menu simply disappears.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Yes, because you are telling the main menu to start from the parent of the document you are currently viewing. I would presume that you want the main menu to show the top-level documents at all times, on all pages? In that case, it would be &startId=`0`. I also don’t see the point in &level=`0`, if you don’t have &level at all it will use all levels, the same as 0.

          You don’t need to have the main menu uncached; it will ease the load on generating the pages a bit if it’s cached with the rest of the page.

          The submenu needs to be uncached so the UltimateParent snippet will get processed first, so its value is available to the Wayfinder snippet.
            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
            • 25803 ☆ A M B ☆
            • 721 Posts
            Thanks very much. It works wonderfully now. I was unsure what the "ultimate" actually meant, but I see that by default it means the immediate parent that pages are nested in whereas pages on the same level as the immediate parent are in effect aunts/uncles.

            The level thing was making it work in a particular way before. I’ve set it to 1 so I don’t have to hide the submenus with CSS.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              The "ultimate" means it will work up the tree until it reaches the top-level (ultimate) parent document. So if you’re in a page that’s three or four levels deep, it will return the top-level grandparent.

              By default it doesn’t stop until it reaches a document whose parent is 0 (a top-level document) since it can’t go any further, but it can be set to stop after x levels.

                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