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

    My plan is to have a ditto call to retrieve the most recent document and display it in template A. Then below that I’d like to display all subsequent documents in template B. Is it possible to filter out the one document from the first Ditto call? Can I pass the id Ditto is retrieving to the second instance?
      I twitch because I care....and drink too much coffee.
      • 16278
      • 928 Posts
      You can set a different template chunk for the first listed item in a single Ditto call, using &tplFirst for that one, and &tpl for the remainder.
      smiley KP
        • 11975
        • 2,542 Posts
        Hi,

        you can use the below snippet to exclude ids retrieved from previos ditto call.
        Let’s call it previousID.

        <?php
        
        $calls = (isset($dittoIDs)) ? explode(',',$dittoIDs) : FALSE ;
        $ids = array();
        $delimiter = (isset($delimiter)) ? $delimiter : ',';
        
        if(is_array($calls) && count($calls)>0){
        	
        	foreach($calls as $dittoID){
        		
        		$exitingDocIDs = $modx->getPlaceholder($dittoID.'_ditto_resource');
        		
        		if($exitingDocIDs){		
        			foreach($exitingDocIDs as $k=>$datas){			
        				$my_ids[] = $datas['id'];
        			}
        			$ids = (count($ids)>0) ? array_merge($ids,$my_ids) : $my_ids;
        		}
        	
        	}
        
        	if(count($ids)>0) return implode($delimiter,$ids);
        }
        ?>
        


        Here is a sample

        //First call:
        [!Ditto? &id=`firstcall`!]

        //then get ids from the first to exclude them from the second ditto call
        [!Ditto? &id=`secondcall` &filter=`id:[[previousID? &dittoIDs=`firstcall`]]:2` &localFilterdelimiter=`:`!]

        hope that helps

        :)
          Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
          • 26310
          • 130 Posts
          Hmmm,

          The above snippet isn’t working yet. As far as I can tell. When I open the Ditto console it comes up with a backend filter as such: id::2

          That seems to say the snippet isn’t returning a value??? I’m going to keep tinkering with it and see if I can get it to work. Thanks for the responses.

          UPDATE: Ok so in the parameter localFilterDelimiter, the "D" just needs to be capitalized. Now it returns all the documents including the one from the first Ditto call. Again I’m getting close I’ll post any updates I find.

          The issue seems to be the snippet failing to pull the first Ditto placeholder.
            I twitch because I care....and drink too much coffee.
            • 26310
            • 130 Posts
            Does anyone know how Ditto broadcasts it’s placeholders? I can’t find any documentation anywhere that lists the placeholders. Specifically if I wanted to use the MODx API to query them.
              I twitch because I care....and drink too much coffee.
              • 36416
              • 589 Posts
              Quote from: sbRyGuy at Jan 24, 2010, 01:56 PM

              Does anyone know how Ditto broadcasts it’s placeholders? I can’t find any documentation anywhere that lists the placeholders. Specifically if I wanted to use the MODx API to query them.

              Save parameter example:
              http://modxcms.com/forums/index.php/topic,41876.msg251644.html#msg251644
                • 26310
                • 130 Posts
                I’m a little confused on that post. So do I need to include a separate snippet called save or something? Or do I just use the &save parameter?

                &save=`1`


                Then I should be able to access the ditto placeholders? Sorry for the hand-holding I haven’t delve this far into Ditto before.
                  I twitch because I care....and drink too much coffee.
                  • 26310
                  • 130 Posts
                  I don’t know what exactly happened but it works!

                  The goal was to have two ditto calls, one to pull the most recent article with image, then in a separate part of the page, another Ditto call to pull all posts OTHER THAN the most recent.

                  heliotrope’s solution worked! I changed the page to cached, unchached the previousID call, and cached the Ditto call. I also added a &save=`2` to the first call and bam! Thanks to all who have responded. That save parameter is trickey, I never was able to list all parameters to see who they’re coming out. Even after searching around and finding Marks solution:
                  http://modxcms.com/forums/index.php/topic,20929.msg137250.html#msg137250

                  I never got that to work. I am still interested if anyone knows how to dump the Ditto output to see how the placeholders are formed. Thanks again!
                    I twitch because I care....and drink too much coffee.