G,day all,
thought i would post this little snippet in case anyone else wanted use something similar to the alternative chunk (&tplAlt=`altChunk`) feature of Ditto, but every third time rather than every other time.
I needed this function as i have a list of many items which are floated across the page, with three to a row, and the last item in each row needed a class of ’last’ applied to the list element so as to apply some css which removes the right margin - hence keeping the items flush with the right hand side of the page. Although this example shows how to manipulate every third output from ditto his could easily be adapted to any other number easily if required.
So you need to set up a snippet to work out if we are on the third ’iteration’ of the ditto snippet:
<?php
// SNIPPET NAME: 'thirdLast'
// ditto iterations start from zero, so add 1 to start count from 1
$count = $iteration + 1;
// use modulus function to check if count is divisible by 3
if( ($count % 3) == 0 ) { return ' class="last"'; }
return;
?>
There is no need to use the ’&tplAlt’ parameter in Ditto. Simply modify your normal template chunk to include a call to your snippet like so:
<li [!thirdLast? &iteration=`[+ditto_iteration+]` !] >
Hope someone finds this useful! Any feedback welcome.