We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33992 ☆ A M B ☆
    • 455 Posts
    Hi,
    I want to Use Destroy Tree as site menu, Destroy Tree has codes below:
    <script type="text/javascript">
    	<!--
    	d = new dTree('d');
    
    	d.add( docId ,  parentId  , title , link );
    
    	document.write(d);
    	//-->
    </script>

    I want to create the line d.add(.... with wayfinder but i have problem:

    I couldn’t find anything to get the parent id so i decided to use this codes:
    $parent = $modx->getParent($modx->documentIdentifier);

    and created rowTpl like below:
    d.add( [+wf.docid+] , parent id , '[+wf.title+]', '[+wf.link+]' );

    so i need to mix these codes to work together at same time, something like this:
    $parent = $modx->getParent( [+wf.docid+] );
    d.add( [+wf.docid+] , $parent['id'] , '[+wf.title+]', '[+wf.link+]' );

    but you know that this codes never works and if values were correct, output is between <ul> and </ul> that make js codes not work.

    would someone help me to solve it?

    Thanks
    AHHP


      God loves me. 【ツ】


      MODX.ir (Persian Support)

      Boplo.ir/modx/ (Persian)
      • 4310
      • 2,310 Posts
      This is a sample config file, but you can create the chunks manually.
      This only works to two levels as it is.
      I’m sure with some more work it’s possible to extend it.
      <?php
      	
      	$level = 4;
      	$hereClass = ''; 
      	$firstClass = '';
      	$selfClass = ''; 
      	$lastClass = '';
      	$parentClass = '';
      	$levelClass = '';
      
      	$innerClass = '';
      	
      	$outerTpl = '@CODE:<script type="text/javascript">
      				<!--
      				d = new dTree(\'d\');
      				d.add(0,-1,\'My example tree\');
      					[+wf.wrapper+]
      	document.write(d);
      				//-->
      				</script>';
      	
      	$innerRowTpl = '@CODE:d.add( [+wf.docid+] , [[UltimateParent? &id=`[+wf.docid+]` &topLevel=`1`]] , [+wf.title+], [+wf.link+] );
      	[+wf.wrapper+]';
      	
      	$innerTpl = '@CODE:	[+wf.wrapper+]';
      	
      	$rowTpl = '@CODE:d.add( [+wf.docid+] , 0 , [+wf.title+], [+wf.link+] );[+wf.wrapper+]';                   
      ?>
        • 4310
        • 2,310 Posts
        Here’s perhaps a better solution.
        Create a snippet with the code below.
        Call it in your template or page.
        Should work at all levels on docs that are published and not hidden from the menu:
        <?php
        $siteName = $modx->config['site_name'];
        $output = '';
        $output .=  '<script type="text/javascript">
        				<!--
        				d = new dTree(\'d\');
        				d.add(0,-1,\'My example tree\');';
        $result = mysql_query('SELECT * FROM `modx_site_content` WHERE `published`="1" AND `hidemenu`="0" ORDER BY `parent` ASC ');
        while($row = mysql_fetch_array($result))
        {
        $output .=  'd.add( '. $row['id'] . ' , '. $row['parent'] . ' , \''. $row['pagetitle'] . '\', \'[~'. $row['id'] . '~]\');'."\n";
        }
        $output .=  '
        	document.write(d);
        				//-->
        				</script>';
        return $output;
        ?>
          • 4310
          • 2,310 Posts
          Here’s a screen shot of it working on a MODx install.
          If anyone wants me to create a zip with everything in it let me know.
            • 33992 ☆ A M B ☆
            • 455 Posts
            Thank you vary much David for your excellent solutions grin
            I think your snippet is the best & clear solution for use Destroy Tree as site menu. wink
              God loves me. 【ツ】


              MODX.ir (Persian Support)

              Boplo.ir/modx/ (Persian)
              • 4310
              • 2,310 Posts
              It’s a pleasure to help smiley