We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14883 ☆ A M B ☆
    • 450 Posts
    I’m trying to get chunk objects, and put their name, description and value into a return template. This isn’t working:
    $returnTpl = '<tr><td>[[+name]]</td><td>[[+description]]</td><td>[[+snippet]]</td></tr>';
    $forach ($chunks as $chunk) {
      $chunk->toPlaceholders();
      $return .= $modx->getChunk($returnTpl);
    }
    


    None of the placeholders are being set.

    I can see from the API docs that chunk objects do inherit the ->toPlaceholders() method. But what placeholders does it set?

      • 4172
      • 5,888 Posts
      if $chunks are xpdo-objects you can try:

      $template = '<tr><td>[[+name]]</td><td>[[+description]]</td><td>[[+snippet]]</td></tr>';
      
      foreach ($chunks as $chunkobj){
      $chunk = $modx->newObject('modChunk');
      $chunk->setCacheable(false);
      $return .= $chunk->process($chunkobj->toArray(), $template);	
      }
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 22303 MODX Staff
        • 10,725 Posts
        You don’t need to call modChunk::toPlaceholders() -- just pass the properties to the getChunk() call that you want set as placeholders. The process() method uses this to set the properties as placeholders and then unsets those and restores any that were overwritten in the scope of the chunk.
          • 22295
          • 153 Posts
          The process() method uses this to set the properties as placeholders and then unsets those and restores any that were overwritten in the scope of the chunk.

          This raised a question - i use process() in the following way (which works) - but now after I see your reply, I doubt if I should setPlaceholders or i can pass the extra tags in an array?

          class memberPost extends modResource {
              public function process($properties= null, $content= null) {
          	$this->xpdo->toPlaceholders($this->getManyDetails('MemberPostEmbeds'));
          	parent :: process($properties, $content);
          	return $this->_content;
              }		
          }

          (code is a fragment only)

          I’ve looked at modResource.class and modtemplatevar.class to understand how this works. is that correct?

          another question - is there anyway to get the template/chunk name used to render this view in the process() ? as far as i see - not. but if ’yes’ it would be a very good place to handle per-view caching (by chunk name).

          Thanks