We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30585
    • 833 Posts
    Hi there,

    I’d like to dynamically retrieve the content of a MODx Revo document into another one and I understand that the GetResources snippet is designed to do just that like the GetField does on Evo.

    There’s simply no documentation or example of the basic calls I should use. Can someone point me to some help or any alternative to this?

    Thanks
      A MODx Fanatic
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: treigh at Jan 26, 2010, 02:19 PM

      I’d like to dynamically retrieve the content of a MODx Revo document into another one and I understand that the GetResources snippet is designed to do just that like the GetField does on Evo.
      getResources is for summarizing Resources, similar to Ditto.

      If all you want to do is get a field from an object in the MODx core, try a simple snippet like this, which I call getValue:
      <?php
      $value = '';
      if ($object = $modx->getObject($class, $modx->fromJSON($where))) {
          $value = $object->get($field);
      }
      return $value;
      ?>

      You could then call this with a variety of arguments to get a piece of MODx data. To get the content of the Resource with id 12:
      [[getValue? &class=`modResource` &field=`content` &where=`{"id":12}`]]

      To get the username of the User with based on the current Resource’s editedby value:
      [[getValue? &class=`modUser` &field=`username` &where=`{"id":[[*editedby]]}`]]
        • 30585
        • 833 Posts
        Quote from: OpenGeek at Jan 26, 2010, 03:28 PM

        Quote from: treigh at Jan 26, 2010, 02:19 PM

        I’d like to dynamically retrieve the content of a MODx Revo document into another one and I understand that the GetResources snippet is designed to do just that like the GetField does on Evo.
        getResources is for summarizing Resources, similar to Ditto.

        If all you want to do is get a field from an object in the MODx core, try a simple snippet like this, which I call getValue:
        <?php
        $value = '';
        if ($object = $modx->getObject($class, $modx->fromJSON($where))) {
            $value = $object->get($field);
        }
        return $value;
        ?>

        You could then call this with a variety of arguments to get a piece of MODx data. To get the content of the Resource with id 12:
        [[getValue? &class=`modResource` &field=`content` &where=`{"id":12}`]]

        To get the username of the User with based on the current Resource’s editedby value:
        [[getValue? &class=`modUser` &field=`username` &where=`{"id":[[*editedby]]}`]]


        Brilliant, Opengeek. It worked fabulously. I’ll spend some time getting myself used to this beast. It’s simply incredible.

        Thanks again
          A MODx Fanatic
          • 30585
          • 833 Posts
          OpenGeek,

          A quick question. I’ll be using this sipped to load form data like country names in a select box.
          Is there any downside to doing that you think?
            A MODx Fanatic
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: treigh at Jan 26, 2010, 04:41 PM

            A quick question. I’ll be using this sipped to load form data like country names in a select box.
            Is there any downside to doing that you think?
            Are you saying you are storing <option> HTML elements in the content of a Resource? I’m not sure I follow...
              • 30585
              • 833 Posts
              Yes I was thinking of that, but i just remembered something called "chunks". I can achieve that easily with chunks.

              Doing this will help reduce the code.

                A MODx Fanatic