We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40122
    • 330 Posts
    Hi all,

    I have a search query that out puts a Ditto.

    Think is it actually prints the Ditto code to the page like a string eg: [!Ditto? &parents=`134` &documents=135 &tpl=`usedtempchunk`!]

    Is there a way to get round this at all?

    Code looks like:
    while ($row = mysql_fetch_array($resultmain )) {
      echo "[!Ditto? &parents=`134` &documents=" . $row['id'] . " &tpl=`usedtempchunk`!]";
    }


    Thanks!
      • 4041
      • 788 Posts
      Give this a try:

      <?php
      $output ='';
      while ($row = mysql_fetch_array($resultmain )) {
          $output .= $modx->runSnippet("Ditto", array(
              'parents'   => '134',
              'documents' => $row['id'],
              'tpl'       => 'usedtempchunk'));
      }
      return $output;
      ?>
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 4172
        • 5,888 Posts
        I think you can collect the ids and run ditto once:

        $ids = array();
        while ($row = mysql_fetch_array($resultmain )) {
            $ids[] = $row['id'];
        }
        return   $modx->runSnippet("Ditto", array(
                'documents' => implode(',',$ids),
                'tpl'       => 'usedtempchunk'));
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 40122
          • 330 Posts
          Thanks guys - turns out it was happy if I added double braces: [[!Ditto....