We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5683
    • 96 Posts
    Hi,
    I’ve created a simple menu snippet that, like DropMenu, produces an hierarchical list of pages.

    The main difference is that only the documents that are related to the current page are listed (i.e. its children and its ancestors’ children), and the snippet works with any number of levles.

    The snippet now is very primitive (no CSS styling at all), but it shouldn’t be hard to modify it if you need more features (I probably won’t -- I am not a web designer, and I don’t know much about CSS!)

    //SimpleMenu 0.1
    //Luca Allulli December 2005
    //License: GNU General Public License 2
    
    //Begin param
    $rootid=isset($rootid)? $rootid: 0;
    $pageid=isset($pageid)? $pageid: $modx->documentIdentifier;
    //End param
    
    $output="";
    
    $children=$modx->getDocumentChildren($pageid);
    if(!empty($children)) {
    	foreach($children as $child) {
    		if($child['id']!=$pageid)
    			$item='<li> <a href="[~'.$child['id'].'~]">'.$child['pagetitle']."</a></li>\n";
    		else
    			$item="<li>".$child['pagetitle']."</li>\n";
    		$output.=$item;	
    	}	
    	$output="<ul>\n".$output."</ul>\n";	
    }
    
    $pid=$pageid;
    
    if($pid==rootid)
    	$goon=false;
    else {
    	$goon=true;
    	$ris=($modx->getParent($pid));
    	$oldid=$pid;
    	$pid=$ris['id'];
    }
    
    while($goon) {
    	$children=$modx->getDocumentChildren($pid);
    	$before=true;
    	$out1="";
    	$out2="";
    	foreach($children as $child) {
    		if($child['id']!=$pageid)
    			$item='<li> <a href="[~'.$child['id'].'~]">'.$child['pagetitle']."</a></li>\n";
    		else
    			$item="<li>".$child['pagetitle']."</li>\n";
    		if($before)
    			$out1.=$item;
    		else
    			$out2.=$item;
    		if($child['id']==$oldid)
    			$before=false;
    	}
    	$output="<ul>\n".$out1.$output.$out2."</ul>\n";
    	$oldid=$pid;
    	if($pid==$rootid)
    		$goon=false;
    	else {
    		$ris=($modx->getParent($pid));
    		$pid=$ris['id'];
    	}
    }
    return $output;
    
      • 26435
      • 1,193 Posts
      I really like the idea. I have been using an eto snippet called "ListChildOrSibs", but I abandoned it because it does not respect the "Show in Menu" box being unchecked. Does your snippet check a documents Show in menu status?

      -sD-
        Husband, Father, Brother, Son, Programmer, Atheist, Nurse, Friend, Lover, Fighter.
        All of the above... in no specific order.


        I send pointless little messages
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Doesn’t look like it; the field to look for is "hidemenu". If that’s set to 1 then the item should not be shown; if it’s 0 is should be shown.

        DropMenu has this:

        	function filterHidden($var) {
        		return (!$var['hidemenu']==1);
        	}
        

          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
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Why couldn’t you just use {!DropMenu?startDoc=`[*parent*]`!]
            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
            • 26435
            • 1,193 Posts
            Quote from: sottwell at Dec 03, 2005, 10:40 AM

            Why couldn’t you just use {!DropMenu?startDoc=`[*parent*]`!]

            Really? It’s that simple?
            Gosh... Thanks Susan. I feel like a big dummy head. I have been searching for ever-more extravagant ways of acomplishing this daunting task, but I should have known it would come back to DropMenu.

            -sD-
              Husband, Father, Brother, Son, Programmer, Atheist, Nurse, Friend, Lover, Fighter.
              All of the above... in no specific order.


              I send pointless little messages
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Well, and the MODx variables. Amazing what you can accomplish with a little creative use of them! Take a look at the site_content table structure, and you’ll see all the things you can use [*pagevariable*] for. And browsing the system_settings table shows all the [(variables)] for site-wide stuff that’s available. You can also access them as $modx->config[’sitewide’], as well as a few other odds and ends that get stuck in that array. I find the document parser class file fascinating reading; I learn something more that can be done every time I read through it. Also echoing the $_SESSION from time to time is quite enlightening as to what user information is readily available.
                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
                • 25663 MODX Staff
                • 12,272 Posts
                Just wait for the new parser when it becomes totally recursive with snippets as parameteres of snippets that have snippets as parameters with TVs mixed in judiciously. wink
                  Ryan Thrash, MODX Co-Founder
                  Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                  • 26435
                  • 1,193 Posts
                  Quote from: rthrash at Dec 03, 2005, 12:43 PM

                  Just wait for the new parser when it becomes totally recursive with snippets as parameteres of snippets that have snippets as parameters with TVs mixed in judiciously. wink

                  What?
                  could you repeat that... I missed what you just said?

                  -sD-
                    Husband, Father, Brother, Son, Programmer, Atheist, Nurse, Friend, Lover, Fighter.
                    All of the above... in no specific order.


                    I send pointless little messages
                    • 33337
                    • 3,975 Posts
                    I think, it would be something like this

                    [!mysnippet? &param=`[[myothersnippet? &param=`[*myTV*]`]]` &param2=`[*anotherTV*]`!]
                    


                    Hope this helps smiley

                    regards,

                    zi
                      Zaigham R - MODX Professional | Skype | Email | Twitter

                      Digging the interwebs for #MODX gems and bringing it to you. modx.link
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      I’m looking forward to better support for using snippets and tvs inside of snippet code.
                        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