We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51142
    • 9 Posts
    Hi.
    I'm completely new to Modx. I've started developing my first site and gotten to the point of using my first snippet - getResources.
    For the life of me I cannot make it work at all.
    I've even stripped it right down to the the simplest call [[!getResources? ]] which I've put into the body of the pre-installed 'Base' template code. Then I assigned that template to a simple document with two child documents - all documents are published and not hidden from menu.
    When I viewed the document there was no output. So I added a call to get phpinfo to the template to see what would come up. Still nothing.
    Here's the template code

    <html>
    <head>
    <title>[[++site_name]] - [[*pagetitle]]</title>
    <base href="[[++site_url]]" />
    </head>
    <body>
    [[*content]]
    <?php phpinfo(); ?>
    [[!getResources? ]]
    </body>
    </html>

    and in the content of the document I've just added the string 'Basic content' which does show up when I view the document, but nothing else appears - neither the output of phpinfo() nor the output of getResources.

    I have Modx installed on a standard webhost and I know php is running properly, not least because the Modx UI wouldn't appear if it wasn't.

    Anybody be able to help me here?

    This question has been answered by multiple community members. See the first response.

      • 47401
      • 295 Posts
      can you explain exactly what it is your trying to do? additional parameters are required for the getresources to work.

      see here for more info.
      https://rtfm.modx.com/extras/revo/getresources

      so in this case, the parent id (in a comma separated list) would show the menus of all child pages

      [[getResources? &parents=`choose_an_id,another_id,one_more_id`]]
      [ed. note: comp_nerd26 last edited this post 8 years, 10 months ago.]
        • 51142
        • 9 Posts
        Sure. My goal is to create a pretty standard grid of templated links to other pages. So (as per tutorials) I'm going to use the getResources snippet.
        I had set up a template that contained a fully configured call to getResources passing a tpl for the presentation, along with the parents id of the root document from which I wanted to gather the resources. That didn't work so I began to peel everything back to find out what I was doing wrong and I've brought it right down to the basic code shown above.

        As far as I can see from the documentation / help sites at very least that basic call to [[!getResources ]] should produce a (Json?) object output that will be displayed on the page (as I say all of the documents are 'published' and all are not 'hidden from menus'). The documentation also seems to indicate that without passing a parentids parameter it will take the current document as the parent.

        I added the call to phpinfo() just as a debug statement to see if somehow it's failing to execute the php code. Should I now at least get the output of phpinfo?
        • discuss.answer
          • 47401
          • 295 Posts
          can you take a look at the error log. its in Manage - Reports - Error Log and see if it displays any error messages. becuase modx supresses error messages and outputs it to the error log.
          • discuss.answer
            • 47401
            • 295 Posts
            you cant call php code from within the template. you have to create a snippet, for example call it phpinfo.
            the snippet should show

            <?php
            echo phpinfo();
            return true;
            


            and in the template call the snippet

            [[phpinfo]]
              • 22840
              • 1,572 Posts
              Try the following and add it to your template:

              [[getResources? 
              &parents=`1`
              &tpl=`yourchunk`
              &limit=`5`
              ]]


              Then create a chunk called yourchunk with the following:

              <p>[[+pagetitle]]</p>

              See if that works
                • 51142
                • 9 Posts
                Ahh, right (on the php code snippet) - thanks.

                So, the error log is showing problems creating a thumbnail

                [2015-09-23 08:33:26] (ERROR @ blah/core/model/phpthumb/phpthumb.class.php : 1596) PHP warning: getimagesize(blah/a b.png): failed to open stream: No such file or directory
                [2015-09-23 08:33:26] (ERROR @ /connectors/system/phpthumb.php) phpThumb was unable to generate a thumbnail for: blah/core/cache/phpthumb/blah__srcc267c794e1f00316d0f4d39a58f1924a_par5df3dad6621628fd102555d4b8000f6e_dat0.jpeg
                [2015-09-23 08:33:26] (ERROR @ /connectors/system/phpthumb.php) Error outputting thumbnail:
                OutputThumbnail() failed because !is_resource($this->gdimg_output) in file "phpthumb.class.php" on line 572
                [2015-09-23 08:34:07] (ERROR @ blah/core/model/phpthumb/phpthumb.class.php : 1596) PHP warning: getimagesize(blah/storyimages/a b.png): failed to open stream: No such file or directory
                [2015-09-23 08:34:07] (ERROR @ /connectors/system/phpthumb.php) phpThumb was unable to generate a thumbnail for: blah/core/cache/phpthumb/blah__src50c5516f852cbc32b12d5c6201b1c83d_paradf896d45f319fa323d889e84ccb98c5_dat0.jpeg
                [2015-09-23 08:34:07] (ERROR @ /connectors/system/phpthumb.php) Error outputting thumbnail:
                OutputThumbnail() failed because !is_resource($this->gdimg_output) in file "phpthumb.class.php" on line 572

                (Note I've anonymised the urls a little).
                Could it be the <space> in the image name that's causing all this trouble?
                • discuss.answer
                  • 51142
                  • 9 Posts
                  Quote from: paulp at Sep 24, 2015, 11:06 AM
                  Try the following and add it to your template:

                  [[getResources? 
                  &parents=`1`
                  &tpl=`yourchunk`
                  &limit=`5`
                  ]]


                  Then create a chunk called yourchunk with the following:

                  <p>[[+pagetitle]]</p>

                  See if that works

                  It worked! Thanks for that. So I have to have a tpl?
                  • discuss.answer
                    • 47401
                    • 295 Posts
                    or use limit 0 for unlimited amount of pages.
                      • 47401
                      • 295 Posts
                      Quote from: usmhot at Sep 24, 2015, 11:20 AM
                      Quote from: paulp at Sep 24, 2015, 11:06 AM
                      Try the following and add it to your template:

                      [[getResources? 
                      &parents=`1`
                      &tpl=`yourchunk`
                      &limit=`5`
                      ]]


                      Then create a chunk called yourchunk with the following:

                      <p>[[+pagetitle]]</p>

                      See if that works

                      It worked! Thanks for that. So I have to have a tpl?
                      #
                      yes. its looping through each page, and outputting the chunk. in the chunk specify page properties, TV's like above