We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19599
    • 33 Posts
    Quote from: BobRay at Jun 24, 2016, 09:23 AM
    Is $tpl a chunk object you've just created, or is it the name of a real chunk? If it's the latter, you can just do this:

    $output .= $modx->getChunk($tpl, $resourceArray);


    If $tpl is a temporary chunk you're creating, I don't know why your code wouldn't work unless the chunk has no content or doesn't contain the correct placeholders.


    the code breaks at
    $resourceArray = $resource->toArray();

    That's what's confusing me. If $resource is of type modResource then toArray() should work. But it doesn't
      • 3749
      • 24,544 Posts
      I don't know if your code has changed, but at one point $tpl was the *name* of a chunk, but I think you were using it as if it were an object.

      You can try this (where $tpl is the name of the chunk from getOption() and you don't manipulate it in any way):

      $output = '';
      $resourceGroup = $modx->getObject('modResourceGroup', array('name' => 'name of resource group'));
      
      $resources = $resourceGroup->getResources();
      
      foreach($resources as $resource) {
          if (! $resource instanceof modResource) {
               /* error */
          } else {
              $resourceArray = $resource->toArray();
              $output .= $modx->getChunk($tpl, $resourceArray);
          }
      
      }
      
      return $output
      ;


        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