We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • I’m trying to use the &save parameter which is supposed to assign Ditto to a template variable, but it errors with:
    PHP error debug
    Error: Object of class ditto could not be converted to string
    Error type/ Nr.: - 4096
    File: /var/www/foo/htdocs/manager/includes/document.parser.class.inc.php
    Line: 733
    Line 733 source: $content= str_replace($matches[0], $replace, $content);

    According to the source code for Ditto, the placeholders available should be
    [+ditto_object+]
    [+ditto_resource+]


    Google turns up nothing - is the feature still supported?

    Thanks!
      MAPLEDESIGN MODX development and MODX web design and custom development. Proud to serve UK and International clients!
      • 1122
      • 209 Posts
      Hi,

      &save parameter does not assign Ditto’s result to template variable, but sets a resource in the global namespace. I am frequently using this parameter and the correct scheme is as follows:
      <?php
      $params = array(
        'id' => 'unique', /* 1 */
        'parents' => '2,5',
        'tpl' => '@CODE:[+id+][+pagetitle+][+content+]',
        'save' => '3', // do not output anything, set placeholders only
        /* ... remaining parameters ... */
      );
      // run Ditto
      $modx->runSnippet('Ditto', $params);
      // fetch results
      $placeholder = $modx->getPlaceholder('unique_ditto_resource'); /* 2 */
      // now you can access results...
      $placeholder[0]['pagetitle'] // <- contains pagetitle of first retrieved document
      $placeholder[1]['content'] // <- content of second retrieved document
      // ... for further processing
      // ...
      ?>
      

      Use print_r($placeholder) to see structure of returned array; also please notice unique id passed within $params /* 1 */ -> later /* 2 */ it is used as prefix while fetching resource saved by Ditto.
      • Ah thanks Alik, I was misunderstanding the parameter, thinking it was like Wayfinder’s &ph option.
          MAPLEDESIGN MODX development and MODX web design and custom development. Proud to serve UK and International clients!
          • 26310
          • 130 Posts
          How are you pulling these placeholders? Do you need to include a separate snippet? In the above code chunk, do you have to manually add those id variables?
            I twitch because I care....and drink too much coffee.