We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25638
    • 15 Posts
    Sorry for the bandwidth on a newbie question, but is there a snippet or web page that has the actual PHP code needed to create a snippet that gets the documents from the server in the order of the Menu Index so that a tree menu can be produced for the entire site?
      • 25638
      • 15 Posts
      Just for context, I need to fill up my javascript with something like this:

      d = new dTree(’d’);

      d.add(0,-1,’My example tree’);
      d.add(1,0,’Node 1’,’example01.html’);
      d.add(2,0,’Node 2’,’example01.html’);
      d.add(3,1,’Node 1.1’,’example01.html’);
      d.add(4,0,’Node 3’,’example01.html’);
      d.add(5,3,’Node 1.1.1’,’example01.html’);
      d.add(6,5,’Node 1.1.1.1’,’example01.html’);
      d.add(7,0,’Node 4’,’example01.html’);
      d.add(8,1,’Node 1.2’,’example01.html’);
      d.add(9,0,’My Pictures’,’example01.html’,’Pictures I\’ve taken over the years’,’’,’’,’img/imgfolder.gif’);
      d.add(10,9,’The trip to Iceland’,’example01.html’,’Pictures of Gullfoss and Geysir’);
      d.add(11,9,’Mom\’s birthday’,’example01.html’);
      d.add(12,0,’Recycle Bin’,’example01.html’,’’,’’,’img/trash.gif’);

      document.write(d);
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        You could use Wayfinder for this, using custom chunk templates for the various parts of the necessary output. There are parameters for generating the level (your nodes) and you can use Wayfinder’s placeholders for displaying the various values relevant to each individual document being listed (such as the menu index, which would correspond to your sub-nodes). You can also use placeholders for any TVs associated with the documents, such as an image path.

        Or you could use a different javascript that would build your menus based on the simple unordered lists that Wayfinder generates by default. http://www.prodevtips.com/2008/07/06/jquery-treeview-with-modx-wayfinder/
          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
          • 25638
          • 15 Posts
          Thanks for the link. I have seen this before and had preferred to use JQuery. Being a newbie, I still don’t quite get how this hangs together.

          WayFinder is being told to get documents starting with ID=18 for English and ID=19 for German. Ok, but when it returns the rows from MySql --- what is the connection to asd.js so that asd.js can display the tree? What goes in to the chunks or snippets and how do they get referenced? How does it all hang together? I’m ok on the CSS side, so no help needed there. It’s the mechanics of putting it all together in MODx that is a little baffling.

          I think once I understand all of this, then I probably can use any JS Tree with WayFinder, correct?
            • 3749
            • 24,544 Posts
            I’m not a JS guru, but I’m thinking that you can use Wayfinder to generate the HTML code that you want, then use a snippet in your template with $modx->regClientStartupScript() to inject your JS into the <head> section of the document. $modx->regClientCSS() will inject the CSS there too if you prefer not to pull it into your template directly.

              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Your Wayfinder chunk tpls will be the key to this. Wayfinder can generate any output, including javascript code! All you have to do is use a line of the code for the row template, replacing the variable values with the appropriate Wayfinder placeholders.

              To get a better understanding, look at a default Wayfinder-generated unordered list, and realize that each part (the outer ul tags, inner ul tags and each li tag) is generated using a default set of templates.

              http://modxcms.com/forums/index.php/topic,34176.msg207851.html#msg207851
                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
                • 25638
                • 15 Posts
                I don’t think I am getting this. I need to create multiple nested levels. As far as I can tell from the WayFinder documentation, it only goes to 2 levels. And since the documentation does not give an example of a tree, I still don’t see how to connect the JQuery tree example to it.

                Going back to the JQuery tree example, if someone would be nice enough to spell out the step-by-step instructions on what has to happen to make it work with a multiple-nested UL/LI/UL/LI/UL/LI/UL/LI tree (4 levels) then I will assemble all of it and create a video tutorial that will make this feat crystal clear, step-by-step for the benefit of all. I’ll also provide a CSS file.

                Thanks in advance to anyone who is willing to take this on!
                  • 34193
                  • 330 Posts
                  [[Wayfinder? &startId=`0` &level=`4`]]

                  Will provide the following structure

                  <ul>
                  <li> level 1 </li>
                  <ul>
                  <li>Level 2</li>
                  <ul>
                  <li>level 3</li>
                  <ul>
                  <li>level 4</li>
                  </ul>
                  </ul>
                  </ul>
                  </ul>
                    • 25638
                    • 15 Posts
                    Um, thanks, but there is certainly more to it and the &level does not seem necessary as not putting it in will still show the whole UL/LI/UL/LI/UL/LI/UL/LI --- so what is the value here with this specific parameter? I don’t think this suggestion will result in a full tree?
                      • 34193
                      • 330 Posts
                      Um yes that is all there is to it

                      The level parameter limits it to 4
                      multiple-nested UL/LI/UL/LI/UL/LI/UL/LI tree (4 levels)

                      check out http://www.cww.org.uk/test.html

                      to see the result a UL of UL’s which is what you asked for.