We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35418
    • 23 Posts
    Hi guys, I’ve been trying to write some code with this magnificent MODx framework, I’ve come a long way now, but yet another challenge, been keeping me busy for two days now laugh

    Using Revo.
    I managed to get the parent when retrieving a single blog post (since I’m building my own blog).

    BUT, when I try to display the parent in the frontpage, I get nothing returned.

    The code for my snippet is this:
    <?php
    $field = $modx->getParent($id,'pagetitle');
    return $field['pagetitle'];


    And the code I’m using on my blog-post-retriever is included in a screenshot on line 22.

    Anyone has an idea what I’m doing wrong? I hope it’s just a small thing, because I’ve tried about 15 ways to do it and all failed.
      • 4172
      • 5,888 Posts
      you can use the getResourceField - snippet
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 3749
        • 24,544 Posts
        You’re missing an argument. It should be:

        $field = $modx->getParent($id, 1, 'pagetitle');


          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
          • 35418
          • 23 Posts
          Quote from: BobRay at Jun 19, 2011, 07:49 PM

          You’re missing an argument. It should be:

          $field = $modx->getParent($id, 1, 'pagetitle');




          Hey thanks for the tip, it still doesn’t work though, I get nothing replied. Don’t know what I’m overlooking so I will check out getResourceField too smiley

          Update:
          Using resourcefield I got this:
          [[+getResourceField? &id='5']]


          Which returns: Personal
          Which is OK.

          But when I put it like this, since the category is dynamic:
          [[+getResourceField? &id='[[*parent]]']]


          I get nothing returned.

          Anyone?
          My guess is that I am trying to get the parent of the ’Home’ page. Since I’m including the script on the Home page?

          When I print parent I get a ’0’ (zero). But when I echo the pagetitle, it does give me the correct title for the child...

          Update2:
          Ok one step further now:
          [[getResourceField? &id=`[[+id]]` &field=`parent`]]

          This now returns me the correct parent number. How, how do I get the title?

          Because this:
          [[getResourceField? &id='[[getResourceField? &id=`[[+id]]` &field=`parent`]]']]

          ..doesn’t seem to work...

          Last update:
          Solved! YEASHHHHHHHHHHHHHHHHHHH! rolleyes shocked cool laugh grin

          [[!getResourceField? &id=`[[getResourceField? &id=`[[+id]]` &field=`parent`]]`]]


          Explanation:
          In the Snippet guidelines it says to alternate cached and uncached snippets when placing them inside of eachother.
          It’s explained to do so like this:
          [!snippet? &snippet2='[[snippet2]]'!]


          But actually putting it like that doesn’t work.
          But like this it works:
          [[!snippet? &snippet2='[[snippet2]]']]
            • 3749
            • 24,544 Posts
            First, all docs at the root of the Resources tree have no parent resource, so you’ll never get anything returned for them.

            I think what you want is this to get the pagetitle of the current page’s parent (when it has one):

            [[getResourceField? &id=`[[*parent]]` &field=`pagetitle`]]
              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
              • 35418
              • 23 Posts
              Quote from: BobRay at Jun 20, 2011, 11:40 AM

              First, all docs at the root of the Resources tree have no parent resource, so you’ll never get anything returned for them.

              I think what you want is this to get the pagetitle of the current page’s parent (when it has one):

              [[getResourceField? &id=`[[*parent]]` &field=`pagetitle`]]


              As you can read in my last reply before this one, I discovered what needed to be done wink

              Turned out like this:
              [[!getResourceField? &id=`[[getResourceField? &id=`[[+id]]` &field=`parent`]]`]]