Smarty - Thank god for books! 
Was working on my project today and had to loop through an array. After every 3rd record had to break the table row and start a new one. Sounds easy right. Only one problem I’m using smarty and NO WHERE in the documentation is it noted that there is a built in counter for loops. So I figure I’ll make another array of numbers to be my counter - right. Works on small stuff but this time it won’t work. No matter how I nest the foreach’s and the if’s - the output will be wrong. Go to take a look at section and cycle… Hmmm - nothing that will suit my simple needs.
Darn it - all I need is a simple counter for the dang loop!!! There has got to be one somewhere! Go and pull out “Essential PHP Tools” by David Sklar. I know they talk about looping with Smarty in the book (quickly glanced over it when I received it - Still reading “Advanced PHP Programming” by George Schlossnagle). And there it is - the iteration property of the foreach loop. Darn it - why couldn’t I find it on the online documentation. Look again at the online docs - and sure enough there it is all the way at the bottom. I didn’t see it for whatever reason (though it really isn’t explained well on the online docs). Maybe it is because I was so busy looking at the examples . Since none of the examples used it - I saw no reason to look lower then Example 7.5. No code or pictures - no sense looking there
.
Anyway - it was a good thing I had the book because I know I never would have noticed the reference to it in the online docs. Here is a direct quote of what it says directly below Example 7-5:
Foreach-loops also have their own variables that handle foreach properties. These are indicated like so: {$smarty.foreach.foreachname.varname} with foreachname being the name specified as the name attribute of foreach
iteration
iteration is used to display the current loop iteration.Iteration always starts with 1 and is incremented by one one each iteration.
first
first is set to true if the current foreach iteration is the first one.last
last is set to true if the current foreach iteration is the last one.show
show is used as a parameter to foreach. show is a boolean value, true or false. If false, the foreach will not be displayed. If there is a foreachelse present, that will be alternately displayed.total
total is used to display the number of iterations that this foreach will loop. This can be used inside or after the foreach.