We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44854
    • 21 Posts
    Can we get getresources output to a php file as array or json string?
      • 54886
      • 3 Posts
      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.
        • 3749
        • 24,544 Posts
        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