We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19369
    • 1,098 Posts
    Hi, is there any snippet that returns the Resource depth/level (for MODx Evolution)?

    Example:

    Home Depth="0"
    Services Depth="0"
    Service1 Depth="1"
    Service2 Depth="1"
    SubService1 Depth="2"
    SubService2 Depth="2"
    Contact Us Depth="0"
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Wayfinder does have the &levelClass parameter that will add the level number to a given string (such as level1, level2 etc) to use as a classname attribute, but I don’t know if it otherwise can be persuaded to display the number of 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
        • 19369
        • 1,098 Posts
        Hi, I have found a snippet that does just that, here’s the link: http://www.gregorysmart.com/2010/05/27/guest-post-count-levels-in-modx/
        Thanks Greg!
          • 11858
          • 130 Posts
          Great piece of code there, very handy. I was wondering if someone could help extending it further?

          I have my snippet:

          <?php
          $output = '';
          $id = $modx->documentIdentifier;
          $levelcount = count($modx->getParentIds($id));
          if ($levelcount == 1) {
              $output = '{{sideNav2deep}}';
          } elseif ($levelcount == 2) {
              $output = '{{sideNav3deep}}';
          } elseif ($levelcount == 3) {
              $output = '{{sideNav4deep}}';
          } elseif ($levelcount == 4) {
              $output = '{{sideNav5deep}}';
          } else $output= '{{sideNav}}';
          return $output;
          ?>
          


          Is there a way to detect that there are no more children of the current document and display a different chunk?

          What I am trying to achieve is BBC Sport style navigation: http://news.bbc.co.uk/sport where you click on Football, you have the parent page at the top of the list (Football) highlighted, and then the children of Football. Click Premier League, and you go deeper again. But click results and you go no deeper, the children of premier league still show. With the snippet above, it would go to results but not have any children as that would be the last in the list. So I need a way for it to automatically detect and load a suitable chunk. But this may not be the case all the time! - Which makes me think that it should be a tickbox in a TV that lets the user specify.

          What’s the best solution?

          Cheers


            • 11858
            • 130 Posts
            After sleeping on it, I think a TV where a user specifies if they want the nav to end is the solution as there is no definite rule when the children show or do not show.

            I think writing it down helped me sort it out in my head!