On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Can we get getresources output to a php file as array or json string?
    • if you foreach iterate json alone, you have an object of objects,even if you pass it as a true parameter,if you are looping through the first parameter.
      • The short answer is, not easily. All MODX snippets, including getResources, return one big string. You could possibly create Tpl chunks for getResources that included delimiters and then parse the output, but it's going the long way around.

        The usual solution is to create your own snippet that gets the same array of resources with getCollection() (just like getResources does). That will give you a PHP array of Resource objects, which you can loop through and create the output you want.

        You can convert each resource object into an array with $resource->toArray().

        You can also use Tpl chunks with $modx->getChunk('ChunkName', $fields) where $fields is an array of placeholder names and their values. Sometimes it's as easy as $fields = $resource->toArray().
          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