We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30694
    • 46 Posts
    This looks neat. I’m going to try it out! Thank you!
      • 17883
      • 1,039 Posts
      Just create a csutom phx modifier (snippet) "phx:remainder":

      <?php
      $remainder=($output+1) % 3;  //whatever tpl you wish to change, here every third
      return $remainder;
      ?>


      Then call it in your template:

      ...
      <li class="listitem[+ditto_iteration:remainder:is=`0`:then=` third`+]">
      ....
        • 10881
        • 4 Posts
        I have a similair question about the usage of an alt chunk. I tried the solution offered above but i can’t get it to work.

        I’m currently working on a blueprint based layout, which uses an <ul> to display a clientlist distibuted over 5 columns.

        I used the following code:
        <ul class="nobullets"<div class="span-4 quiet colborder"><li class="solidline"><a href="[~[+id+]~]" class="nav">[+menutitle+]</a></li></div></ul>


        In this layout blueprint requires a "last" class every 5th item. Also, I don’t want the "colborder" class to appear on every 5th item. I use ditto to generate the list, so i thought i could use the ditto_iteration function in combination with the PHx call, like the example above shows. But somehow my code doesn’t read properly..

        The ditto call:
        [!Ditto? &id=`klanten` &parents=`53` &orderBy=`pagetitle ASC` &display=`all` [+phx:if=`[+ditto_iteration+]`:is=`4`:or:is=`8`:or:is=`12`:or:is=`16`:or:is=`20`:then=`&tpl=`klant-item-last``:else=`&tpl=`klant-item``+]!]


        Could anybody help me out?


          • 7231
          • 4,205 Posts
          You need to place the PHx inside the Ditto tpl chunk. It will iterate through the output rather than the input. If I understood correctly.
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don&#39;t know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 10881
            • 4 Posts
            So if i understood correctly, i have to put the PHx call like this:

            [!Ditto? &id=`klanten` &parents=`53` &orderBy=`pagetitle ASC` &display=`all` &tpl=`[+phx:if=`[+ditto_iteration+]`:is=`4`:or:is=`8`:or:is=`12`:or:is=`16`:or:is=`20`:then=`klant-item-last`:else=`klant-item`+]`!] 


            Because it doesn’t show a difference.. it’s awkward that the call does seems to do something, because it does take the tpl "klant-item", it only doesn’t use the tpl "klant-item-last" on the 4th, 8th, 12th, ect.

            Maybe i miss understood, and you meant i have to place the ditto_iteration inside the "klant-item" chunk?
            But i can’t figure out how, because i use to different chunks to achieve the desired effect. I use the following chunks:

            chunk "klant-item":
            <div class="span-4 quiet colborder"><li class="solidline"><a href="[~[+id+]~]" class="nav">[+menutitle+]</a></li></div>


            chunk "klant-item-last":
            <div class="span-4 quiet last"><li class="solidline"><a href="[~[+id+]~]" class="nav">[+menutitle+]</a></li></div>


            I also tried to combine the 2 chunks with the following ditto and PHx call:

            ditto call:
            [!Ditto? &id=`klanten` &parents=`53` &orderBy=`pagetitle ASC` &display=`all` &tpl=`klant-item`!] 
            


            chunk "klant-item":
            <div class="span-4 quiet [+phx:if=`[+ditto_iteration+]`:is=`4`:or:is=`8`:or:is=`12`:or:is=`16`:or:is=`20`:then=`last`:else=`colborder`+]"><li class="solidline"><a href="[~[+id+]~]" class="nav">[+menutitle+]</a></li></div>


            I’m stuck.. what am i doing wrong?
              • 7231
              • 4,205 Posts
              You do not add the PHx to the Ditto call, you use it inside the Ditto tpl chunk that you use for the output display. Then you would use the PHx to change/add the class name according to the iteration.

              So in the Ditto call you would have &tpl=`tplChunkName` then in the chunk you would use the PHx:

              <div class="[+ditto_iteration:remainder:is=`0`:then=` last`+]">

              And don’t forget to change the phx modifier to $remainder=($output+1) % 5; to trigger on the 5th iteration.
                [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                Something is happening here, but you don&#39;t know what it is.
                Do you, Mr. Jones? - [bob dylan]
                • 10881
                • 4 Posts
                Tnx for your help, it worked!
                  • 7231
                  • 4,205 Posts
                  Happy you got it running. It is easy to get confused in the process. By default PHx is available inside of Dittp tpls and is a great way of having smart tpl chunks. Very cool.
                    [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                    Something is happening here, but you don&#39;t know what it is.
                    Do you, Mr. Jones? - [bob dylan]
                    • 34017
                    • 898 Posts
                    what a great thread. you learn a lot by going through the bugs/feature requests in jira
                      Chuck the Trukk
                      ProWebscape.com :: Nashville-WebDesign.com
                      - - - - - - - -
                      What are TV's? Here's some info below.
                      http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
                      http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
                      • 9995
                      • 1,613 Posts
                      In my ditto I use:

                      [+ditto_iteration:is=`0`:or:is=`3`:then=`large`+]

                      then the first and third one has class large.
                        Evolution user, I like the back-end speed and simplicity smiley