5 * -------------------------------------------------------------
10 * Author: Monte Ohrt <monte@ispi.net>
11 * Purpose: make an html table from an array of data
12 * Input: loop = array to loop through
13 * cols = number of columns
14 * table_attr = table attributes
15 * tr_attr = table row attributes (arrays are cycled)
16 * td_attr = table cell attributes (arrays are cycled)
17 * trailpad = value to pad trailing cells with
19 * Examples: {table loop=$data}
20 * {$table loop=$data cols=4 tr_attr='"bgcolor=red"'}
21 * {$table loop=$data cols=4 tr_attr=$colors}
22 * Taken from the original Smarty
23 * http://smarty.php.net
24 * -------------------------------------------------------------
26 function tpl_function_html_table($params, &$template_object)
28 $table_attr = 'border="1"';
38 throw new Template_Exception("html_table: missing 'loop' parameter", $template_object);
42 $output = "<table $table_attr>\n";
43 $output .= "<tr " . tpl_function_html_table_cycle('tr', $tr_attr) . ">\n";
45 for($x = 0, $y = count($loop); $x < $y; $x++
)
47 $output .= "<td " . tpl_function_html_table_cycle('td', $td_attr) . ">" . $loop[$x] . "</td>\n";
48 if((!(($x+
1) %
$cols)) && $x < $y-1)
51 $output .= "</tr>\n<tr " . tpl_function_html_table_cycle('tr', $tr_attr) . ">\n";
55 // last row, pad remaining cells
56 $cells = $cols - $y %
$cols;
58 for($padloop = 0; $padloop < $cells; $padloop++
) {
59 $output .= "<td " . tpl_function_html_table_cycle('td', $td_attr) . ">$trailpad</td>\n";
65 $output .= "</table>\n";
69 function tpl_function_html_table_cycle($name, $var)
71 static $names = array();
78 if(!isset($names[$name]) ||
$names[$name] == count($var)-1)
85 return $var[$names[$name]];