We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11807
    • 21 Posts
    Hi everyone, I started use Modx only some day ago and I have a little problem:
    for my site i choose to use 2 different menu, one horizontal (the main sections) that never change and one vertical that change when you choose one of the items in the horizontal.
    The problems comes when I click on the pages that don’t have subpages: the vertical submenu become empty... In fact I must mod Wayfinder to make possible this thing: when the output is null (no links show in menu), it show the links of the parent document.

    Can someone help me? rolleyes
    Thanks a lot (and sorry for my english).
      • 10487 MODX Staff
      • 1,535 Posts
      No need to mod Wayfinder, all you need to do is to create another small snippet to wrap the logic and control which Wayfinder call is executed.

      Something like this, for example:
      <?php
      if (count($modx->getChildIds($modx->documentObject['id'],1)) == 0 || $modx->runSnippet('Wayfinder', array('startId'=>$modx->documentObject['id'])) == '') {
          // no children or output from wayfinder will be an empty string, so use the parent ID as the start ID
          return $modx->runSnippet('Wayfinder', array('startId'=>$modx->documentObject['parent'], 'level'=>'1'));
      } else {
         // has children and output will not be an empty string, so use this page's ID as the start ID
         return $modx->runSnippet('Wayfinder', array('startId'=>$modx->documentObject['id'], 'level' => '1'));
      }
      ?>
      

      You just need to customise the runSnippet() calls to use your own snippet parameters (in the second argument of the runSnippet call, see how the snippet parameters are passed in as an array - that’s what you will need to add to if you use custom parameters).

      Then, call this snippet on the page where you want the horizontal menu to be displayed. smiley

      Hope that helps,
      Garry
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 11807
        • 21 Posts
        Thanks Thanks Thanks!!!
        It works nicely! wink
          • 11807
          • 21 Posts
          sorry if I abuse of you... but the code above only works with first level subfolder, from the 2nd level subfolders don’t seem to work...
          example, this is the tree of my site

          homepage (folder)
          telephones
          addr
          maps
          news (folder)
          newspapers_extracts (folder)
          2007 (folder)
          2006 (folder)
          ext1
          ext2
          books_extracts (folder)
          ....
          reservedarea (folder)
          links
          admins
          things_to_do

          all works fine in reservedarea & in homepage, but don’t works when the pages open are ext1 or ext2. huh

          thanks again rolleyes