We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6850
    • 12 Posts
    I want to display the current parent document page title on all of the child documents of a parent in my template.

    For example, if I have a primary navigation of "Home, Company, Products, Contact", and for the "Company" parent document, I have child documents of "About Us", "Our History", "Our Locations". Laid out, it would be:

    Home
    Company
    > About Us
    > Our History
    > Our Locations
    Products
    Contact

    I want to place in my template a snippet call to include the name "Company" on each of the pages "About Us", "Our History", and "Our Locations." When you were on Products (or Products Children) it would say "Products". Same with Contact, it would say "Contact". If there were children documents of the children documents it would still say the parent page title name in the snippet.

    Is there is a snippet that would do this? If so, what is the snippet name and how do I call it in the template?
      • 25663 MODX Staff
      • 12,272 Posts
      DropMenu is really what it looks like in your layout above.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 10487 MODX Staff
        • 1,535 Posts
        Hi ddmobley, it’s possible with a slightly modified version of sottwell’s UltimateParent snippet... copy and paste the following code into a new snippet:

        //-- Modified version of sottwell's UltimateParent snippet
        //-- Outputs pagetitle of the Ultimate Parent doc
        
        $id = $modx->documentIdentifier;
        $pid = $modx->getParent($id,1,"id,pagetitle");
        if($pid['id'] == 0) { return $id; }
        while ($pid['id'] != 0) {
            $id = $pid['id'];
            $pagetitle = $pid['pagetitle'];
            $pid = $modx->getParent($id,1,"id,pagetitle");
        }
        return $pagetitle;
        


        To call the snippet in the template, assuming you have called the snippet ultimateParentTitle, you can use: [[ultimateParentTitle]]

        Hope that helps,

        Garry
          Garry Nutting
          Senior Developer
          MODX, LLC

          Email: [email protected]
          Twitter: @garryn
          Web: modx.com
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Maybe one of the page trail or breadcrumb snippets would also be useful?
            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
            • 6850
            • 12 Posts
            Quote from: garryn at Jun 12, 2006, 04:51 AM

            Hi ddmobley, it’s possible with a slightly modified version of sottwell’s UltimateParent snippet... copy and paste the following code into a new snippet:

            //-- Modified version of sottwell's UltimateParent snippet
            //-- Outputs pagetitle of the Ultimate Parent doc
            
            $id = $modx->documentIdentifier;
            $pid = $modx->getParent($id,1,"id,pagetitle");
            if($pid['id'] == 0) { return $id; }
            while ($pid['id'] != 0) {
                $id = $pid['id'];
                $pagetitle = $pid['pagetitle'];
                $pid = $modx->getParent($id,1,"id,pagetitle");
            }
            return $pagetitle;
            


            To call the snippet in the template, assuming you have called the snippet ultimateParentTitle, you can use: [[ultimateParentTitle]]

            Hope that helps,

            Garry

            Garry, I used the snippet verbatim and it returns a number which I assume is the document ID. Perhaps it isn’t configured quite right?
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Try this:
              //-- Modified version of sottwell's UltimateParent snippet
              //-- Outputs pagetitle of the Ultimate Parent doc
              
              $id = $modx->documentIdentifier;
              $pid = $modx->getParent($id,1,"id,pagetitle");
              if($pid['id'] == 0) { return $modx->documentObject['pagetitle']; }
              while ($pid['id'] != 0) {
                  $id = $pid['id'];
                  $pagetitle = $pid['pagetitle'];
                  $pid = $modx->getParent($id,1,"id,pagetitle");
              }
              return $pagetitle;
              
                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
                • 6850
                • 12 Posts
                Yes, Susan, that worked quite nicely. Thank you!
                  • 33337
                  • 3,975 Posts
                  Original question/problem solved. If you have more questions please start a new thread.

                  regards,

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

                    Digging the interwebs for #MODX gems and bringing it to you. modx.link