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

    About 3 years ago I had some help putting this snippet together for MODx 95:

    <?php
    $page = $modx->documentObject[’id’];
    $parent = $modx->getParent($page,1,’id’);
    $plt = $modx->getParent($page,1,’longtitle’);
    $modx->setPlaceholder(’parentTitle’, $plt[’longtitle’]);
    $url = $modx->makeURL($parent[’id’]);
    return $url;
    ?>

    I have tried using it in .963 and I get the following error:

    « MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource:
    « `` is not numeric and may not be passed to makeUrl() »

    It works fine in .95 but not in .962-.963

    The name of the snippet is [!PageParent!]. The purpose is to fetch the url of the parent doc along with the longtitle of the parent doc. Below is how I use it:

    <a href="[!PageParent!]/" title="[+parentTitle+]" >[+parentTitle+]</a>

    Can anyone see why it is now breaking in .963?
      • 7231
      • 4,205 Posts
      Try changing:
      $page = $modx->documentObject['id']; 

      to
      $page = $modx->documentIdentifier; 
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 21136
        • 103 Posts
        I tried

        $page = $modx->documentIdentifier;

        and it didn’t make a difference. It still gives the error. I tried the script one line at a time and it crashed when these 2 lines are in the snippet:

        $url = $modx->makeURL($parent[’id’]);
        return $url;

        ie. error...

        « `` is not numeric and may not be passed to makeUrl() »
          • 3749
          • 24,544 Posts
          Are you sure every document you call it in is has a parent and that parent is published?

            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
            • 7231
            • 4,205 Posts
             $url = $modx->makeURL($parent['id']);
             return $url;


            You need to check the value returned for $parent[’id’], since according to the error this is not returning an ID (integer). If I test this in a top level document (with parent 0) it fails with the same error you describe. If thsi snippet is running on all pages then you should do a check to see if there is a valid parent first.

            <?php
            $parentId = $modx->documentObject['parent'];
            if ($parentId > 0) {
                $page = $modx->documentIdentifier;
                $parent = $modx->getParent($page,1,'longtitle');
                $modx->setPlaceholder('parentTitle', $parent['longtitle']);
                $url = $modx->makeURL($parentId);
                return $url;
            }
            ?>


            Works on my test environment wink
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don&#39;t know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 21136
              • 103 Posts
              Thanks dev_cw... !!!

              I works perfectly smiley

              This community is awesome