We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1607
    • 72 Posts
    How can I call Ditto in php code?
      • 4310
      • 2,310 Posts
      Something like :
      <?php
      $params['startID'] = 9;
      $params['showInMenuOnly'] = 1;
      $params['commentsChunk'] = '';
      $params['randomize'] = 1;
      $params['sortDir'] = 'ASC';
      $params['display'] = '20';
      $params['tpl'] = 'TenantSummary';
      $params['noResults'] = 'No Documents Found';
      $output = $modx->runSnippet('Ditto', $params);
      return $output;
      ?>
        • 1607
        • 72 Posts
        Thank you!!!
        Results of this call placed in array?
        How can I see this array?
        How can I call element of this array?
          • 33992 ☆ A M B ☆
          • 455 Posts
          Quote from: Andrey_V at Dec 10, 2008, 03:17 AM

          Thank you!!!
          Results of this call placed in array?
          How can I see this array?
          How can I call element of this array?

          $modx->runSnippet() returns string.
            God loves me. 【ツ】


            MODX.ir (Persian Support)

            Boplo.ir/modx/ (Persian)
            • 1607
            • 72 Posts
            Thank you!!!
              • 1607
              • 72 Posts
              Now I can output Ditto result on my page.
              But I can’t see elements of Ditto such as:

              $title = SomeArray[bla-bla-bla]

              What array keep all results of Ditto?
              And how can I output elements of this array?

              O maybe I can use another metod?
              I need this elements for XML file creating.
                • 10449
                • 956 Posts
                I need this elements for XML file creating.

                Just use a chunk that acts as a template for the Ditto-output! This can be anything: plain text, HTML, JS and... yep, even XML smiley

                e.g.

                $params['tpl'] = 'myXMLChunkName'; // points to a chunk that holds your template (tags, placeholders...)

                or
                $params['tpl'] = '@CODE <node id="[+id+]">[+pagetitle+]</node>'; // etc.


                whether you use modx to return / echo this final string in the calling modx document, or whether you use something like file_put_contents() to save a static file on your server is up to you...
                  • 33992 ☆ A M B ☆
                  • 455 Posts
                  Ditto can returns output as XML itself. use &format parameter.

                  I think using this parameter is easier wink
                    God loves me. 【ツ】


                    MODX.ir (Persian Support)

                    Boplo.ir/modx/ (Persian)
                    • 1607
                    • 72 Posts
                    Yes, I do this.
                    And now I try to use Ditto in ajax query.
                    I have <div> on the page. When I press button JS function send ajax query to the server - php file. If I create php file - all OK. XML file is good. When I try use Ditto - I get error message.

                    How can I dinamically change Ditto and place it results on the page?
                      • 33992 ☆ A M B ☆
                      • 455 Posts
                      What is error message?

                      If you want to use Ditto for ajax, you can create snippet like below:
                      <?php
                      .
                      .
                      $startID = $modx->db->escape($_GET['startID']);
                      $sortDir = $modx->db->escape($_GET['sortDir']);
                      .
                      include( Ditto snippet );
                      ?>


                      put this snippet in a blank document. now you can request data from this document and get response.
                      in this case, xmlResponseText will be Ditto output. you can do same with getting &format=xml in your ajax query for get XML response.


                      also you can get simple data without Ditto, by doing it yourself!
                        God loves me. 【ツ】


                        MODX.ir (Persian Support)

                        Boplo.ir/modx/ (Persian)