We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16858
    • 58 Posts
    When a user works their way through the menuing system and comes to the end of a branch, and there is no menu left to display, I would like to display the tree from startID=`1`.

    I tried doing this by altering the WayFinder snippet at the very end of the code to read:

    ...
    //Process Wayfinder
    $output = $wf->run();
    
    // This code added by me.
    // -------------------
    if (!$output) {
        $output = $modx->runSnippet('Wayfinder? &startID=`1` &level=`1` &sortBy=`menutitle`');
    }
    // End code added by me.
    // ------------------
    
    //Ouput Results
    if ($wf->ph) {
        $modx->setPlaceholder($wf->ph,$output);
    } else {
        return $output;
    }
    ?>


    This idea doesn’t work at all. undecided Can someone share some insight on how I should do this?

    Thanks in advance.
      • 10487 MODX Staff
      • 1,535 Posts
      The problem is how you are passing the parameters into the $modx->runSnippet() call

      Anyway, here is a slight variation (tweaked to your needs) on something I coded up for someone the other day - it seems to be quite a popular request just lately laugh You can use this in place of your standard Wayfinder call:
      <?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'=>'1', 'level'=>'1','sortBy'=>'menutitle'));
      } 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','sortBy'=>'menutitle'));
      }
      ?>
      

      Doing it this way means you don’t have to hack the Wayfinder code which makes it easier when it comes to upgrading to the next release wink

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

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 16858
        • 58 Posts
        That worked PERFECTLY!! Thanks so much.

        I had read about the $modx-runSnippet call but never saw documentation on how to apply parameters. Thanks for quick tutorial!