We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46253
    • 3 Posts
    I use ditto to show the last entries of a specific parent. For this I am using the following call:

    [!Ditto? &parents=`5` &orderBy=`createdon DESC` &display=`3`
    
    &total=`4` &extenders=`summary` &tpl=`tpl_news` &truncLen=`160` &truncOffset=`20` !]


    I now want my website to continuously loop through a specific range of parent ids and change the parents parameter every other second.

    The result should be a "slideshow" of the content called by the ditto calls.

    No special effects, no design (except the one provided by the template).

    Is there an easy way to manage this?
      • 4172
      • 5,888 Posts
      if I understand, what you want, is to call every second a resource with your Ditto-call on it by ajax and send the parents-property to your ajax-resource with the ajax-request.

      http://api.jquery.com/load/

      if you don't want to code it by yourself, there are a ton of ajax-sliders out there.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 13428 ☆ A M B ☆
        • 1,031 Posts
        Think you want to ranomize the parent parameter of Ditto: could be done like this.

        [!Ditto? &parents=`[[Ditto? &documents=`1,2,3` &display=`1` &tpl=`@CODE[+id+],` &randomize=`1`]]`
        &orderBy=`createdon DESC`
        &display=`3`
        &total=`4`
        &extenders=`summary`
        &tpl=`tpl_news`
        &truncLen=`160`
        &truncOffset=`20`
        !]

          • 46253
          • 3 Posts
          Quote from: Bruno17 at Jan 13, 2014, 12:10 AM
          if I understand, what you want, is to call every second a resource with your Ditto-call on it by ajax and send the parents-property to your ajax-resource with the ajax-request.

          http://api.jquery.com/load/

          if you don't want to code it by yourself, there are a ton of ajax-sliders out there.

          Hey, thank you for your answer. It's not exactly what I want, I will try to make myself more clear. I have a layout-template with this (simplified) content:

          <!DOCTYPE html>
          <html>
            <body>
          
              <div class="col_content">
                [!Ditto? &parents=`5` &orderBy=`createdon DESC` &display=`3` 
                &total=`4` &extenders=`summary` &tpl=`tpl_news` &truncLen=`160` &truncOffset=`20` !]
              </div>
          
            </body>
          </html>


          Now I am looking for a method which replaces this ditto call with another ditto call (or the parents variable) every other second. However I do not want to reload the rest of the page, just the content in the <div>.

          So after 3 seconds or so it should look like this:

          <!DOCTYPE html>
          <html>
            <body>
          
              <div class="col_content">
                [!Ditto? &parents=`6` &orderBy=`createdon DESC` &display=`3` 
                &total=`4` &extenders=`summary` &tpl=`tpl_news` &truncLen=`160` &truncOffset=`20` !]
              </div>
          
            </body>
          </html>


          Is replacing/mutating the ditto call after loading the page even possible?

          Quote from: Jako at Jan 13, 2014, 01:06 AM
          Think you want to ranomize the parent parameter of Ditto: could be done like this.

          [!Ditto? &parents=`[[Ditto? &documents=`1,2,3` &display=`1` &tpl=`@CODE[+id+],` &randomize=`1`]]`
          &orderBy=`createdon DESC`
          &display=`3`
          &total=`4`
          &extenders=`summary`
          &tpl=`tpl_news`
          &truncLen=`160`
          &truncOffset=`20`
          !]


          This will create a randomized ditto call when the page is loaded, but it will not automatically change every other second after the page has been loaded, am i correct?
            • 13428 ☆ A M B ☆
            • 1,031 Posts
            Quote from: lotzki at Jan 13, 2014, 02:39 PM

            [!Ditto? &parents=`[[Ditto? &documents=`1,2,3` &display=`1` &tpl=`@CODE[+id+]` &randomize=`1`]]`
            …
            !]


            This will create a randomized ditto call when the page is loaded, but it will not automatically change every other second after the page has been loaded, am i correct?

            It should change the parents every call (nested snippet calls need to have alternate the cache settings).
              • 4172
              • 5,888 Posts
              this is exactly, what I was talking about. You will need an ajax-request, which does load that part by javascript from server, which can be an empty resource (blank template) just with the Ditto-snippet on it, or a wrapper-snippet with something like that:

              new snippet with name 'getNews':

              if isset($_REQUEST['parents']){
              
                  $properties = array();
                  $properties['parents'] = $_REQUEST['parents']; 
                  $properties['orderBy'] = 'createdon DESC';
                  $properties['display'] = '3';
                  $properties['total'] = '4';
                  $properties['extenders'] = 'summary';
                  $properties['tpl'] = 'tpl_news';
                  $properties['truncLen'] = '160';
                  $properties['truncOffset'] = '20';
                  return $modx->runSnippet('Ditto',$properties);
              
              }


                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 46253
                • 3 Posts
                My bad, got it to work!

                I created this resource:

                <div id="newsticker_vn">[!Ditto? &parents=`6` &orderBy=`createdon DESC` &display=`1`<br />&total=`4` &extenders=`summary` &tpl=`tpl_news` &truncLen=`160` &truncOffset=`20` !]</div>
                <div id="newsticker_hp">[!Ditto? &parents=`5` &orderBy=`createdon DESC` &display=`1`<br />&total=`4` &extenders=`summary` &tpl=`tpl_news` &truncLen=`160` &truncOffset=`20` !]</div>
                <div id="newsticker_ks">[!Ditto? &parents=`7` &orderBy=`createdon DESC` &display=`1`<br />&total=`4` &extenders=`summary` &tpl=`tpl_news` &truncLen=`160` &truncOffset=`20` !]</div>


                and use this script to get the desired ditto calls and loop them:

                <div id="newsticker"></div>
                <script type="text/javascript">
                        function execute() {
                		$( "#newsticker" ).load("[~348~] #newsticker_vn").delay( 300 ).fadeIn( "slow" ).delay( 6000 ).fadeOut( "slow",execute2 );
                	}
                	function execute2() {
                		$( "#newsticker" ).load("[~348~] #newsticker_ks").delay( 300 ).fadeIn( "slow" ).delay( 6000 ).fadeOut( "slow",execute3 );
                	}
                	function execute3() {
                		$( "#newsticker" ).load("[~348~] #newsticker_hp").delay( 300 ).fadeIn( "slow" ).delay( 6000 ).fadeOut( "slow",execute );
                	}
                	execute();
                </script>


                I tried doing all steps in one function but for some reason it was showing every ditto call three times before rotating, no idea why.

                Thank you for your help!
                  • 4172
                  • 5,888 Posts
                  you could of course load all the Ditto - listings at once into another hidden div within your template and load them from there without any ajax-requests.
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!