We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28376
    • 222 Posts
    Lets say i have the following ditto Query

    [!Ditto? &parents=`10,37,9,5,385,30,37` &sortBy=`createdon` &sortDir=`DESC` &total=`12` &tpl=`tpl_editors_choice` &filter=`editorschoice,1` !]
    


    Uses the following template called tpl_editors_choice

    
    <!--Start news item  -->
    <div class="newsitem">
    <p><a href="http://www.mydomain.com/[~[+id+]~]"><img src="http://www.mydomain.com/[+choiceimage+]" alt="[+feature_txt+]" title="[+feature_txt+]" class="thumb" width='160' height='105' /></a></p>
    <p> </p>
    <h2>[+choicetitle+]</h2>
    <p><a href="http://www.mydomain.com/[~[+id+]~]" class='lnkGray'>[+choicetext+]</a></p>
    </div>
    <!--End News item -->
    



    In the template how do I say something if record count is 3 then display this line of code. If not then continue this line of code.


      • 3749
      • 24,544 Posts
      If you’re using Ditto 2.x, [+total+] holds the number of items retrieved, so with PHX (untested):


      [+total:is=`3`:then=`Display This`:else=`Display This Instead`+]

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 16278
        • 928 Posts
        NB [+total+] is only populated when &paginate=`1`.
        smiley KP
          • 28376
          • 222 Posts
          But the question is let’s say you have 20 records and with record count each time when record count hits 3 it will execute that code so within the 20 records it will be executed 5 times
            • 16278
            • 928 Posts
            I’m not quite sure of the arithmetic there, but it looks as if you could use the [+ditto_iteration+] placeholder and some modulo maths to get what you’re after. The placeholder is the sequence number of results in the current page, starting from zero. Using the PHx modifier math, it you could do something like
            [+ditto_iteration:math=`?%4`:is=`3`:then=`Display This on every fourth one`:else=`Otherwise Display This`+]

            where ? is the current value of the placeholder and the percent sign is the PHP modulus division operator.

            If the strings to output will be lengthy, you might prefer to create your own custom PHx modifier, otherwise your template can get messy and difficult to maintain.
            smiley KP
            http://wiki.modxcms.com/index.php/PHx#math.3D.60calculation.60
            http://www.php.net/manual/en/language.operators.arithmetic.php
              • 29201
              • 239 Posts
              i think this is exactly what I’m looking for and i’m wondering if you could post the final code that you used to get this working.

              I need to display this after every 3 record that ditto returns:

              <li class="clear"> </li>


              as you might have guessed i’m using <ul> and <li> for my gallery.

              Thanks!

              I solved this using this:
              <ul class="clean" style="margin-left:-14px;">
                  [[Ditto? &parents=`24` &display=`6`  &orderBy=`pub_date DESC` &tpl=`regularvidtpl` &paginate=`1` &paginateAlwaysShowLinks=`1` ]]
                  
                  [+ditto_iteration:math=`?%4`:is=`3`:then=`<li class="clear"> </li>`:else=`Otherwise Display This`+]
              </ul>  
                   
              <div class="clear"></div>
              
              <div class="grid_11">
                  Showing [+start+] - [+stop+] of [+total+]  Articles
                  [+previous+] [+pages+] [+next+] 
              </div>