We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16357
    • 27 Posts
    I am using Ditto to list out thumbnails from underlying documents. There are four thumbnails per row. Due to margin-issues I need a different class on each fourth thumbnail. The "default" chunk looks like this:
    <div class="productThumb">
    	<a href="[~[+id+]~]"><img src="[+tvThumbnail+]" width="101" height="95" alt="[+title+]" /></a>
    	<p><a href="[~[+id+]~]">[+title+]</a></p>
    </div>

    Every fourth thumb should have this chunk:
    <div class="productThumbRight">
    	<a href="[~[+id+]~]"><img src="[+tvThumbnail+]" width="101" height="95" alt="[+title+]" /></a>
    	<p><a href="[~[+id+]~]">[+title+]</a></p>
    </div>

    The Ditto call looks like this:
    [[Ditto? &tpl=`Produkktbilde` &startID=`9` &descendentDepth=`1` &displayArchive=`0` &total=`200` &summarize=`200`]]

    Is there any simple way to do this?
      • 18397
      • 3,250 Posts
      There is currently no way to do this in Ditto 2 without hacking the code. Ditto 2.1 will offer a feature called conditional templating that would help but it won’t be out for some time. In the meantime, you can change this line:

      $template = $ditto->template->determine($templates,$x,0,$stop,$resource[$x]["id"]);
      


      to
      if ($x % 4 && isset($tplFourth)) {
      $template = $ditto->template->fetch($tplFourth) 
      } else {
      $template = $ditto->template->determine($templates,$x,0,$stop,$resource[$x]["id"]);
      }
      


      You would then use the &tplFourth parameter.
        • 25663 MODX Staff
        • 12,272 Posts
        Very cool mark... thanks! laugh
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 16357
          • 27 Posts
          Thanks a lot smiley
            • 16357
            • 27 Posts
            Hmm I get the following error:
            Parse error: syntax error, unexpected '}' in /manager/includes/document.parser.class.inc.php(748) : eval()'d code on line 918
              • 18397
              • 3,250 Posts
              There should be a semicolon at the end of this line:

              $template = $ditto->template->fetch($tplFourth);
              
                • 16357
                • 27 Posts
                Thanks, I just noticed. I am used to ASP myself and hence things like a ";" just slips my eyes.
                However, now i get class "productThumb" on every first thumb in a row and "productThumbRight" on the three next ones. I wish I was better at PHP so I wouldn’t have to bother you with details like this.
                  • 16357
                  • 27 Posts
                  I solved it by modifying the code to this:
                  $xthumb = 0;
                  for ($x=0;$x<$stop;$x++) {
                  if ($xthumb == 3 && isset($tplFourth)) {
                  $template = $ditto->template->fetch($tplFourth);
                  $xthumb = 0;
                  } else {
                  $template = $ditto->template->determine($templates,$x,0,$stop,$resource[$x]["id"]);
                  $xthumb++;
                  }

                  Thanks for all help smiley