We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20751
    • 122 Posts
    OK. Experimenting. Tried setting up a snippet with the following to test if getparent was working:

    $id = $modx->documentIdentifier;
    $pid = $modx->getParent($id,1,’id’);
    return $pid;

    On the root page I get nothing and on pages inside folders I get "Array". What am I doing wrong?

    I can print $id to the page if I return $id but can’t get $pid!

    Does it matter if I have se friendly urls? Does getParent work if the parent is a folder? Does it matter?

    My page structure is:

    root page
    about (folder)
    page 1
    page 2
    page 3
    services (folder)
    page 1
    page 2
    page 3
    products (folder)
    page 1
    page 2
    page 3

    If that helps someone to troubleshoot!

    Thanks!

    • getParent returns an array, since usually you’ll have more than one item to be returned in the "fields" part of the arguments. So you should have

      $id = $modx->documentIdentifier;
      $pdata = $modx->getParent($id,1,'id');
      $pid=$pdata['id'];
      return $pid;
      
        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
        • 20751
        • 122 Posts
        You know what . . . you consistently point me in the right direction, both in your replies to my posts and in the threads I’ve read that you’ve either started or replied to. Thank you!

        • You know, "parent" is a regular part of any document; outside of snippets or TVs with PHP code you can use [*parent*], inside you can almost always use $modx->documentObject[’parent’]. I frequently use [*parent*] as the value for the DropMenu snippet’s startDoc argument.

          There are some cases where the documentObject may not be available, though, such as in a plugin that acts on the OnWebPageInit event, which is triggered before the documentObject array is set, and then you’d need to use your function.
            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
            • 20751
            • 122 Posts
            I’m just getting to grips with snippets and tvs at the moment . . . haven’t even touched plugins yet. Thanks for the info though! This thing is awesome. I’m looking at the stuff that it can do, thinking "Ah, but I bet it can’t do that". Five minutes later, I find that it can!

            Awesome!

            • document.parser.class.inc.php makes for great bedtime reading wink
                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