We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23050
    • 1,842 Posts
    Update : GetParentTitle becomes GetParentField.
    More and more improvment thanks to the help of mrcou.
    Now GetParentField can be used to call any tv you want of the Parent.

    Snippet code here (and file attached)
    $id=(!isset($id)) ? $modx->documentObject['id'] : $id;
    if($id==0)return;
    $target=(!isset($target)) ? 'pagetitle' : $target;
    $parent = $modx->getParent($id,1,$target);
    $parent = $parent[$target];
    return $parent;


    To call the snippet, juste use [!GetParentField? &id=`[*id*]`!] (to get the title) or [!GetParentField? &target=`introtext` &id=`[*id*]`!] to get the intro (you can now specify the tv you want to display with the &target variable.


    Original post

    Hi,

    Thx to Heliotrope, I managed to build my first snippet, called GetTitleParent laugh

    Here is the code :
    $parent = $modx->getParent($id,1,'pagetitle');
    $parent = $parent['pagetitle'];
    return $parent;


    I call the snippet in a chunk :
    <a href="[~[*parent*]~]">[!GetTitleParent? &id=`[*parent*]`!]</a>


    The nav is like this : Folder 1 (id=13) > Folder 2 (14) > Document A (5)

    But, and that’s the reason why I’m posting now, there’s something strange.

    As I call the chunck in document A, the id of the parent should be 14, right ?
    [~[*parent*]~] builds the good link to Folder 2 but
    [!GetTitleParent? &id=`[*parent*]`!] build a text with id 13 so with the parent of the parent of document A.
    Am I clear ?

    Don’t know how to resolve it. Thx for help smiley
      • 7455
      • 2,204 Posts
      thats because your snippet gets the parent of the id you give it so it does it double first you give it the id of the parent (14) and then in your snippet you are asking for the parent of (14) thats (13) and ask for the title. thats why.

      so you should call it like this I think [!GetTitleParent? &id=`[*id*]`!] or you could change your snippet to automaticly use the curent pageid as id.

      Dimmy
        follow me on twitter: @dimmy01
        • 23050
        • 1,842 Posts
        Yes you’re right ! I use [!GetTitleParent? &id=`[*id*]`!] and it’s perfect now wink

        Thx smiley
          • 23050
          • 1,842 Posts
          Now that all is working, I can propose my "little" Snippet laugh (also in French : http://modxcms.com/forums/index.php?topic=5187)

          Aim of this snippet : If you have such a menu : Folder 1 > Document A, how to get the [*pagetitle*] from Folder 1 while you are running Document A.
          Useful if you want to indicate to your users, in which folder they are.

          I called the Snippet GetParentTitle

          $parent = $modx->getParent($id,1,'pagetitle');
          $parent = $parent['pagetitle'];
          return $parent;


          To call the snippet in your page, juste use [[GetParentTitle? &id=`[*id*]`]]

          Hope this help some noobs like me wink
            • 33337
            • 3,975 Posts
            Great little work man! I was searching to build this myself, but you made it easy for me!

            For those who want it in form of link:

            <a href="[~[*parent*]~]" title="[[GetTitleParent? &id=`[*id*]`]]">[[GetTitleParent? &id=`[*id*]`]]</a>
            


            best regards,

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

              Digging the interwebs for #MODX gems and bringing it to you. modx.link
              • 23050
              • 1,842 Posts
              Quote from: zi at Jun 16, 2006, 09:53 AM

              Great little work man!

              Girl... but I suppose you have some excuses wink I’m french and Perrine is not a name often used laugh
              Happy to see this little snippet is useful wink
                • 33337
                • 3,975 Posts
                Quote from: Perrine at Jun 16, 2006, 10:00 AM

                Girl... but I suppose you have some excuses wink I’m french and Perrine is not a name often used laugh
                Happy to see this little snippet is useful wink
                ouch!

                Nice work Perrine laugh

                I have updated my above post with Link code also.

                Thanks again.

                regards,

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

                  Digging the interwebs for #MODX gems and bringing it to you. modx.link
                  • 23050
                  • 1,842 Posts
                  Update : GetParentTitle becomes GetParentField.
                  More and more improvment thanks to the help of mrcou.
                  Now GetParentField can be used to call any tv you want of the Parent.

                  Snippet code here (and file attached - see the first post)
                  $id=(!isset($id)) ? $modx->documentObject['id'] : $id;
                  if($id==0)return;
                  $target=(!isset($target)) ? 'pagetitle' : $target;
                  $parent = $modx->getParent($id,1,$target);
                  $parent = $parent[$target];
                  return $parent;


                  To call the snippet, juste use [!GetParentField? &id=`[*id*]`!] (to get the title) or [!GetParentField? &target=`introtext` &id=`[*id*]`!] to get the intro (you can now specify the tv you want to display with the &target variable.
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    Oh, yes, I can see where this could be very useful, like the Andreas02 template or YAML or any other template with nice spaces for odd bits of content!
                      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