Thursday, September 6, 2007

Multi-Column Layouts with Smarty/PHP

Developer Kevin Sours had been looking for elegant ways to create multi-column layouts from variously-sized collections in Smarty, and couldn't quite find a plugin that would fit his needs.

As a result, Kevin wrote two plugins we're happy to release under a BSD/Open Source License to the Smarty developer community:

split:
Split works much like "foreach" but instead of iterating over the array an element at a time, it iterates over a set of subarrays of roughly equal size. The motivation is to allow multicolumn layouts without either a lot of ugly smarty markup or requiring the generating page to handle breaking the array down for the column display (which requires encoding the number of columns in the php code).


split_row:
Like split, split_row is a foreach-like structure that returns parts of an array for the purpose of doing mulicolumn layouts. The difference is that split_row returns the values in row order instead of column order.


Feel free to poke at it and give us feedback in comments.

1 comment:

ABTRaju said...

It's not work for me, it will print only first row. Please help.