We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42682
    • 20 Posts
    I'm sorry but I'm a still a little confused how to pass that value into getChunk() would it be something like this?:

    <?php
    /* @var $modx modX */
      
    $c = array(
        'hidemenu' => 0,
        'published' => 1,
    );
    
    $p = array(
        'placholdername' => 'value',
    );
    
    $output = '';
    $children = $modx->resource->getMany('Children', $c);
      
    foreach($children as $child) {
        /* @var $child modResource */
        $fields = $child->toArray();
        $fields['imgSource'] = $child->getTVValue('ProductImage');
        $output .= $modx->getChunk('ThreeImgChunk', $p);
    }
    return $output;


    ...although that admittedly doesn't work. Could you show me where and how I'm supposed to define the associative array?

    Thanks
      • 3749
      • 24,544 Posts
      I think you're very close. If you send the associative array in the getChunk call, you don't to create or set any placeholders in your code.

      Rty just replacing that $p in line 20 with $fields.


      BTW, since it's a snippet, you can always throw in some echo statements along the way to see what you have (and take them out later).

      if (empty($chldren)) {
      
          echo "\nNO Chilodren\n";
      }
      

      echo "\nIMAGE SOURCE: " . $fields['imgSource'];
      

      echo "\nFIELDS: " . var_dump($fields) . "\n";
        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
        • 42682
        • 20 Posts
        What would be the best way to control the order in which each child resource is displayed?

        I've tried in the snippet call like this:

        [[SnippetName &sortBy=`menuindex`]]

        but that didn't seem to work. What else could I do?

        Thanks
          • 3749
          • 24,544 Posts
          Replace lines 4-7 above with this:


          $c = $modx->newQuery('modResource');
          $c->where(array(
              'hidemenu' => 0,
              'published' => 1,
          ));
          
          $sortBy = isset($scriptProperties['sortBy'])? $scriptProperties['sortBy'] : 'menuindex';
          $sortDir = isset($scriptProperties['sortDir'])? $scriptProperties['sortDir'] : 'ASC';
          $c->sortby($sortBy, $sortDir);
          


          Then you can use both &sortBy and &sortDir (ASC|DESC) in the tag to set the sort field and direction.
            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