We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9359
    • 128 Posts
    hi everybody,
    i have a questions about ditto when it's call by snippet...
    How do i add the string for pagination?
    <p>Showing <strong>[+start+]</strong> - <strong>[+stop+]</strong> of <strong>[+total+]</strong> Articles | Page <strong>[+currentPage+]</strong> of <strong>[+totalPages+]</strong></p> <div id="ditto_pages"> [+previous+] [+pages+] [+next+] </div> </div>


    Can i put it inside?
    echo "......";


    My ditto call in snippet is
      $dittoOutput = $modx->runSnippet("Ditto",array(
                'parents' => "4",
                'tpl' => 'lista-tpl',
                'sortBy'=>'pub_date',
                'filter'=> $filter,
                'paginate' = '1',
                'paginateAlwaysShowLinks'= '1',
                'id' = 'onlycat'
            )
           );
    echo $dittoOutput;


    many thx
      "Destiny is not a matter of chance, it's a matter of choice"
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      A snippet should use "return" rather than "echo". Using echo can have the output in places you might not expect it to be.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 9359
        • 128 Posts
        Thx sottwell,
        you have right, also if the output now is ok. i will try to change it.
        The prolem is that i'm not able to activate the pagination.... how can i make the ditto placeholder for pagination by snippet? I have searched the solution in documentation and in forum but i have not found anything... :-(

          "Destiny is not a matter of chance, it's a matter of choice"
          • 16278
          • 928 Posts
          You'd usually just put the pagination placeholders within the page containing the Ditto call (see http://www.pogwatch.com/ditto/ditto-pagination.html). Does the reason you are using a wrapper snippet prevent you doing that?
          :) KP
            • 9359
            • 128 Posts
            Hi kp52,
            unfortunately I can not run ditto in the traditional way, but only within a very complex snippet that makes various checks, otherwise there would be no problem ...

            nobody knows how I can set pagination in this way? :-(
              "Destiny is not a matter of chance, it's a matter of choice"
              • 16278
              • 928 Posts
              Totally untested, but you could try using the getPlaceholder() API call to build the pagination string. NB I've corrected the array value settings in your original post ("=" should be "=>")
              <?php
              $dittoOutput = $modx->runSnippet("Ditto",array(
                          'parents' => "4",
                          'tpl' => 'lista-tpl',
                          'sortBy'=>'pub_date',
                          'filter'=> $filter,
                          'paginate' => '1',
                          'paginateAlwaysShowLinks'=> '1',
                          'id' => 'onlycat'
                      )
                     );
              
              $dittoOutput .= '<p>Showing <strong>' . $modx->getPlaceholder('start') . '</strong> - ';
              $dittoOutput .= '<strong>' . $modx->getPlaceholder('stop') . '</strong> of ';
              $dittoOutput .= '<strong>' . $modx->getPlaceholder('total') . '</strong> Articles | Page ';
              $dittoOutput .= '<strong>' . $modx->getPlaceholder('currentPage') . '</strong> of ';
              $dittoOutput .= '<strong>' . $modx->getPlaceholder('totalPages') . '</strong></p> ';
              $dittoOutput .= '<div id="ditto_pages"> ' . $modx->getPlaceholder('previous'); 
              $dittoOutput .= $modx->getPlaceholder('pages') . $modx->getPlaceholder('next') . '</div> </div>';
              
              return $dittoOutput;
              ?>


              I suspect there's a less long-winded way, as the document parser seems to refer to a collection of all the placeholders to implement getPlaceholder(). If that could be fetched as an array, you could use it with parseChunk() to make a more easily maintained way of forming the pagination links.

              :) KP

              Update: couldn't resist some experimenting, and found that $modx->placeholders does indeed return an array of all the placeholders currently set. So you could set up your pagination code as a chunk with the normal placeholder names, and use $modx->parseChunk() with $modx->placeholders as the second parameter to form the string. Using this property of $modx is referred to in Mary's tutorial at http://codingpad.maryspad.com/2010/01/15/modx-custom-snippet-api/.
              ===
              [ed. note: kp52 last edited this post 14 years, 6 months ago.]
                • 9359
                • 128 Posts
                Many many thx KP!!!!
                i try asap!!!!
                  "Destiny is not a matter of chance, it's a matter of choice"
                  • 9359
                  • 128 Posts
                  The first solution does not works :-(
                    $dittoOutput = $modx->runSnippet("Ditto",array(
                              'parents' => "4",
                              'tpl' => 'lista-tpl',
                              'sortBy'=>'pub_date',
                              'filter'=> $filter,
                              'paginate' => '1',
                              'paginateAlwaysShowLinks'=> '1',
                              'id' => 'onlycat'
                          )
                         );
                  $dittoOutput .= '<p>Showing <strong>' . $modx->getPlaceholder('start') . '</strong> - ';
                  $dittoOutput .= '<strong>' . $modx->getPlaceholder('stop') . '</strong> of ';
                  $dittoOutput .= '<strong>' . $modx->getPlaceholder('total') . '</strong> Articles | Page ';
                  $dittoOutput .= '<strong>' . $modx->getPlaceholder('currentPage') . '</strong> of ';
                  $dittoOutput .= '<strong>' . $modx->getPlaceholder('totalPages') . '</strong></p> ';
                  $dittoOutput .= '<div id="ditto_pages"> ' . $modx->getPlaceholder('previous');
                  $dittoOutput .= $modx->getPlaceholder('pages') . $modx->getPlaceholder('next') . '</div> </div>';
                   
                  return $dittoOutput;


                  the item is showed by ditto but nothing pagination :-(
                    "Destiny is not a matter of chance, it's a matter of choice"
                    • 9359
                    • 128 Posts
                    opss i'm mistake.
                    the solution works great! i have forget to put the id in placeholder like [+onlycat_start+]
                    thx KP.
                    Now i would try other solution more clean...
                      "Destiny is not a matter of chance, it's a matter of choice"