We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50574
    • 70 Posts
    Is it possible to tell Wayfinder to only show certain levels for certain menu items?
    For example, show the second level for a 'range' menu item but not for the 'blog' item.

    I'm currently using Wayfinder in it's simplest form as:
    [[Wayfinder? &startId=`0`&level=`2`]]


    Can I target a certain menu ID and tell it to not show Level 2?

    It's only proving a problem with the blog I've created using the tutorial on the ModX docs site http://rtfm.modx.com/revolution/2.x/case-studies-and-tutorials/creating-a-blog-in-modx-revolution because the posts are showing in the menu at level 2. If I hide the posts from the menu in the page settings they don't show in the blog summary page either.

    Any help would be much appreciated.
      • 23018
      • 353 Posts
      I guess you are overcomplicating things here, but you have a multitude of options to solve this problem:

      1. Use some conditional on the [[+wrapper]] part in your template chunks for rowTpl, innerRowTpl, etc.

      Something like this should do the trick:

      &rowTpl
      <li>
         <a href="[[+wf.link]]">[[+wf.linktext]]</a>
         [[[[+id:is=`5`:or:is=`8`:or:is=`9`:then=`+wf.wrapper`:else=`-`]]]]
      </li>
      


      Hint: You can chain conditional output filters (http://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/input-and-output-filters-(output-modifiers))

      2. I don't know how much chaining will slow down wayfinder, so it might be wise to go for a snippet instead:

      <li>
         <a href="[[+wf.link]]">[[+wf.linktext]]</a>
         [[[[!inArray? &needle=`[[+id]]` &haystack=`5,8,9` &yes=`-` &no=`+wf.wrapper`]]]]
      </li>
      


      The inArray snippet could look like this

      <?php
      /* inArray snippet */
      $needle = $modx->getOption('needle', $scriptProperties, false);
      $haystack = $modx->getOption('haystack, $scriptProperties, false);
      $yes = $modx->getOption('yes', $scriptProperties, '');
      $no = $modx->getOption('no', $scriptProperties, '');
      $delimiter = $modx->getOption('delimiter', $scriptProperties, ',');
      
      if($needle && $haystack){
         $haystack = explode($delimiter , $haystack);
         if(in_array($needle,$haystack){
            return $yes;
         }
         else {
            return $no;
         }
      }
      else {
         return '';
      }
      


      3. Add a radio TV to each resource "displayChildren" and check if it is set to 1 (default) or 0.

      <li>
         <a href="[[+wf.link]]">[[+wf.linktext]]</a>
         [[[[+displayChildren:is=`1`:then=`+wf.wrapper`:else=`-`]]]]
      </li>
      


      Attention: I'm not sure if Wayfinder will set placeholders for TVs, so this might be bad advice...

      ...

      Cheers,

      pepebe [ed. note: pepebe last edited this post 8 years, 10 months ago.]
        Homepage: pepebe.de | MODX snippets (and other stuff) at github: https://gist.github.com/pepebe
        • 50574
        • 70 Posts
        Thanks for this pepebe.

        I ended up moving to PDOMenu and made the &resources= call for specific pages in the menu snippet.
        Not very dynamic but the top level menu items don't need to be for this project.

        Cheers
        • &hideSubmenus will hide all submenus of parents that aren't children of the current ID, but will show submenus of the current resource. It's a nifty parameter, and came in very handy recently.

          That, and a combination of &excludeDocs could be helpful for your purposes.
            Frogabog- MODX Websites in Portland Oregon
            "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
            Having server issues? These guys have MODX Hosting perfected - SkyToaster