I’ve been working with the 960.gs grid and was having a problem with needing to list several grid items but needing to style the first and last items in a row.
after a few searches i didn’t see anything so I wrote this little snippet and wanted to get feedback. after an initial test it seems to be working fine but thought i’d submit it to the community in the event that it might help others or i’d get some feedback on a better approach.
in the grid system (this would really work on anything that you are needing to style the first and last items in a row) i needed to put the class "alpha" or "omega" according for it to clear out the respective left and right margins.
here’s the snippet (i haven’t changed the code to test if the appropriate vars are not properly set)
<?php
//n represents the number of items per row
$n= isset($n) ? $n: "not set";
//current represents the current document
//ditto_iteration starts at 0 so we add 1
$current = isset($current) ? $current + 1 : "not set";
//the code below will always evaluate to 1 for the first item and 0 for the last item in the row
switch($current % $n){
case 1:
return "alpha";
break;
case 0:
return "omega";
break;
}
?>
from my ditto call i use the following in my chunk(in this example i have 3 grid_4 items in a row but "n" could be adjusted to however many items you are listing in a row:
<div class="grid_4 promoBox [!nthItem? &n=`3` ¤t=`[+ditto_iteration+]`!]"
<a href=""><img src="[+thumbnail+]" alt="[+pagetitle+]"/></a>
<h3>[+pagetitle+]</h3>
</div>
hope this helps or perhaps someone has found a cleaner way.