10 * Smarty {html_table} function plugin
13 * Name: html_table<br>
14 * Date: Feb 17, 2003<br>
15 * Purpose: make an html table from an array of data<br>
17 * - loop = array to loop through
18 * - cols = number of columns
19 * - rows = number of rows
20 * - table_attr = table attributes
21 * - tr_attr = table row attributes (arrays are cycled)
22 * - td_attr = table cell attributes (arrays are cycled)
23 * - trailpad = value to pad trailing cells with
24 * - vdir = vertical direction (default: "down", means top-to-bottom)
25 * - hdir = horizontal direction (default: "right", means left-to-right)
26 * - inner = inner loop (default "cols": print $loop line by line,
27 * $loop will be printed column by column otherwise)
33 * {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
34 * {table loop=$data cols=4 tr_attr=$colors}
36 * @author Monte Ohrt <monte@ispi.net>
38 * @link http://smarty.php.net/manual/en/language.function.html.table.php {html_table}
39 * (Smarty online manual)
44 function smarty_function_html_table($params, &$smarty)
46 $table_attr = 'border="1"';
59 $smarty->trigger_error("html_table: missing 'loop' parameter");
63 $loop_count = count($loop);
64 if (empty($params['rows'])) {
65 /* no rows specified */
66 $rows = ceil($loop_count/$cols);
67 } elseif (empty($params['cols'])) {
68 if (!empty($params['rows'])) {
69 /* no cols specified, but rows */
70 $cols = ceil($loop_count/$rows);
74 $output = "<table $table_attr>\n";
76 for ($r=0; $r<$rows; $r++
) {
77 $output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n";
78 $rx = ($vdir == 'down') ?
$r*$cols : ($rows-1-$r)*$cols;
80 for ($c=0; $c<$cols; $c++
) {
81 $x = ($hdir == 'right') ?
$rx+
$c : $rx+
$cols-1-$c;
83 /* shuffle x to loop over rows*/
84 $x = floor($x/$cols) +
($x%
$cols)*$rows;
88 $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[$x] . "</td>\n";
90 $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">$trailpad</td>\n";
95 $output .= "</table>\n";
100 function smarty_function_html_table_cycle($name, $var, $no) {
101 if(!is_array($var)) {
104 $ret = $var[$no %
count($var)];
107 return ($ret) ?
' '.$ret : '';
111 /* vim: set expandtab: */
This page took 0.325768 seconds and 4 git commands to generate.