We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30511
    • 8 Posts
    Hello,

    I wonder if it is possible to create a Link to the first (and in my case the only) child of a folder? I found the FirstChildRedirect Snippet, but am not sure how to use it in my specific case, or if this snippet isn’t the right choice for me.

    So: Site1 shall contain a link to Site1b, while Site1b is the only child of Site1.

    Help would be greatly appreciated.

    Thanks in advance.

    S.
      • 21257 MODX Staff
      • 730 Posts
      The FirstChildRedirect snippet does not create a hyperlink. If you use it in a container, then when your browser requests the URL of that container, modx will output a redirect header, causing the browser to go to the first child document instead.

      You could use a Ditto call to create a hyperlink to the first child:

      [[Ditto? total=`1` &tpl=`@CODE <a href="[~[+id+]~]" title="[+pagetitle+]">[+menutitle+]</a>` ]]
      


      This is untested.
        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
        • 30511
        • 8 Posts
        Quote from: netProphET at Nov 11, 2008, 05:43 AM


        [[Ditto? total=`1` &tpl=`@CODE <a href="[~[+id+]~]" title="[+pagetitle+]">[+menutitle+]</a>` ]]
        


        This is untested.


        I’m fairly new to modx, and confused. is this call (theoretically) all i have to do? or is there more to it?
        i’ve placed your code into my template, and it didn’t work: "&tpl either does not contain any placeholders or is an invalid chunk name, code block, or filename. Please check it."

        i also don’t really understand how this call finds the first child.

          • 21257 MODX Staff
          • 730 Posts
          I was afraid that @CODE call wouldn’t work undecided It’s a shorthand way of specifying an html template for the snippet to use. Normally you supply the name of a Chunk, and Ditto uses the contents of that Chunk as the template.
          I’ll try it out myself and report back once I have it fixed up.
          Aside from that, Ditto, by default, outputs a summary of child documents. In my call, I told it to just output one.
          The template tells Ditto what html to output for each document it summarizes (again, it’s just going to be the one child document in this case).
            Mike Schell
            Lead Developer, MODX Cloud
            Email: [email protected]
            GitHub: https://github.com/netProphET/
            Twitter: @mkschell
            • 30511
            • 8 Posts
            Okay, thank you for the explanation and the thoughts your putting into this.
              • 21257 MODX Staff
              • 730 Posts
              Wow, I can’t get the @CODE bit working in a test site either. I used this technique just a couple of months ago, and even posted about it in the forum here, and I’m sure it was working.

              Anyway, let’s forget about doing it shorthand. Create a chunk, let’s call it FirstChildLink. Use the following in the Chunk code (html).

              <a href="[~[+id+]~]" title="[+pagetitle+]">[+menutitle+]</a>
              


              Now, here’s the Ditto call that will give you what you want:

              [[Ditto? total=`1` &tpl=`FirstChildLink` ]]
              

                Mike Schell
                Lead Developer, MODX Cloud
                Email: [email protected]
                GitHub: https://github.com/netProphET/
                Twitter: @mkschell
                • 30511
                • 8 Posts
                i will try that immediately. smiley
                  • 30511
                  • 8 Posts
                  okay, this is strange.
                  i did both what you suggested: i put the ditto call into a sample page with the ID 70, the child of 70 is 71.
                  the ditto call correctly creates links: but to ID 172, 41 and 14.

                  these three are the last submenu categories on my site.

                  what is wrong?
                    • 4310
                    • 2,310 Posts
                    Ditto, by default, will look for three doc’s to summarize, and if no start id is specified it will start at the site root.
                    Try adding :
                    &startID=`70`
                    to your Ditto call on page 70
                      • 30511
                      • 8 Posts
                      it works like a charm smiley

                      thank you both wink