We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18453
    • 66 Posts
    I have been looking all over the forum and found some pointers but couldn’t get it to work the way I want for ditto:

    I want to be able to have even and odd classes for each li element and first and last class for the first and last one.
    There is a solution for maxigallery, thats just the way it has to be, but I don’t know how to make this work for ditto.

    I know there is a way to have diferent templates/chunks for those with ditto, but that doesn’t suit me..
    This is because the first and last classes don’t have even and odd classes, I would like the first and last element have both classes like this:

    <ul>
    <li class="first even"></li>
    <li class="odd"></li>
    <li class="even"></li>
    <li class="odd"></li>
    <li class="even"></li>
    <li class="odd last"></li>
    </ul>

    For maxigallery:
    http://modxcms.com/forums/index.php/topic,30762.0.html

    For ditto
    Works, but I don’t want to have to specify how many li elements, but want to automate it to have the last li element.
    http://wiki.modxcms.com/index.php/PHx

    I know it should be really easy to do, but I don’t have those skillz yet.
    Thanx for any help in advance!!
      • 4172
      • 5,888 Posts
      you can try:
      for &tpl
      <li class="[+ditto_iteration:is=`0`:then=` first`+][+ditto_iteration:math=`(?+1)%2`:is=`0`:then=` odd`:else=`even`+]"></li>

      and for &tplLast:
      <li class="[+ditto_iteration:math=`(?+1)%2`:is=`0`:then=` odd`:else=`even`+] last"></li>

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

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 33976 ☆ A M B ☆
        • 571 Posts
        I might missunderstand this properly but, according to http://ditto.modxcms.com/files/snippet-ditto-php.html

        tpl User defined chunk to format the documents
        tplAlt User defined chunk to format every other document
        tplFirst User defined chunk to format the first document
        tplLast User defined chunk to format the last document

        Should do the trick
          • 4172
          • 5,888 Posts
          korma, you are right, of course. But you have to create four chunks for that.
          with this phx-solution there are only two. If we had a value for testing if it is the last iteration, we would need only one chunk.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 18453
            • 66 Posts
            Thanx bruno, It works great! grin
              • 18453
              • 66 Posts
              korma: the reason why this works better is because, this way the odd class can be combined with a last class, with the standard tplLast template you can’t aply both to it..
                • 33976 ☆ A M B ☆
                • 571 Posts
                Got it. Thanks for the clearing smiley