We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19787
    • 28 Posts
    I have a number of documents in a nested tree structure like so :

    Home
    - Doc 1
    -- Doc 1.1
    -- Doc 1.2
    ---Doc 1.2.1
    ---Doc 1.2.2
    -- Doc 1.3
    - Doc 2
    -- Doc 2.1
    -- Doc 2.2
    -- Doc 2.3
    - Doc 3
    -- Doc 3.1
    -- Doc 3.2
    -- Doc 3.3

    I would like ditto to output all the documents in the ascending order they appear in the tree like the following :

    Doc 1
    Doc 1.1
    Doc 1.2
    Doc 1.2.1
    Doc 1.2.2
    Doc 1.3
    Doc 2
    Doc 2.1
    Doc 2.2
    Doc 2.3
    Doc 3
    Doc 3.1
    Doc 3.2
    Doc 3.3


    I am using "orderBy" =>"menuindex ASC", however it just does not seem to output in the correct order. I have tried "sortDir" =>"ASC", but this also does not work.

    I have upgraded mysql server to 5.1.34 as i have read about the sort issues with mysql 5.0.51

    If i use the default [!wayfinder!] snippet call, it outputs all documents in the correct order i want. Is there a similar output in Ditto? Or do i need to create a custom sort function?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Is there a reason why you need to use Ditto and not Wayfinder for this? You can use tpl chunks to control the appearance and content of Wayfinder; it doesn’t have to just be links.
        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
        • 19787
        • 28 Posts
        Thanks for the advice. I did not realise Wayfinder could output Template Variables.

        I am actually using it in a bit of a hacky way. I wanted to output an array of all the documents (with TVs and in the tree order) so i can use it in my own custom PHP script. I tried doing it with SQL but gave up pretty quick after a join too many! And I could not find any examples of how to do this using the API (which i am sure is much cleaner and the recommended method).

        For anyone that might find it useful here is the snippet code (slightly modified so needs testing!)

        
        //Get an array of all documents and TVs in the tree order
        
        $documents = $modx->runSnippet("Wayfinder", array(
        	"startId" =>1,
        	"level" =>5,
        	"removeNewLines" =>"true",
        	"outerTpl" =>"@CODE:[+wf.wrapper+]",
        	"rowTpl" =>"@CODE:[+wf.docid+] ,[+wf.subitemcount+] ,[+wf.title+] ,[+myCustomTvs+] ,[+myOtherCustomTvs+] ,[+ohMyAnotherCustomTvs+] ,[+wf.wrapper+]"
        ));
        
        //remove the extra item that gets added to end of array
        $d = substr($documents, 0, -1);
        //Explode values from wayfinder seperated by comma
        $docs = (explode(" ,",$d));
        //Create an arrary for each doc
        $docArray = array_chunk($docs,6);
        
        print_r ($docArray);
        
        



        Wayfinder seems very similar to Ditto. Which one is more optimal (speed wise) to use? I know Ditto does a lot more, but I noticed the number of DB queries was slightly less when using Wayfinder than Ditto (at least for what i was trying to do).