Source for file function.html_table.php
Documentation is available at function.html_table.php
* Smarty {html_table} function plugin
* Purpose: make an html table from an array of data<br>
* - loop = array to loop through
* - cols = number of columns
* - rows = number of rows
* - table_attr = table attributes
* - tr_attr = table row attributes (arrays are cycled)
* - td_attr = table cell attributes (arrays are cycled)
* - trailpad = value to pad trailing cells with
* - vdir = vertical direction (default: "down", means top-to-bottom)
* - hdir = horizontal direction (default: "right", means left-to-right)
* - inner = inner loop (default "cols": print $loop line by line,
* $loop will be printed column by column otherwise)
* {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
* {table loop=$data cols=4 tr_attr=$colors}
* @link http://smarty.php.net/manual/en/language.function.html.table.php {html_table}
$table_attr = 'border="1"';
$loop_count = count($loop);
if (empty($params['rows'])) {
$rows = ceil($loop_count/ $cols);
} elseif (empty($params['cols'])) {
if (!empty($params['rows'])) {
/* no cols specified, but rows */
$cols = ceil($loop_count/ $rows);
$output = "<table $table_attr>\n";
for ($r= 0; $r< $rows; $r++ ) {
$rx = ($vdir == 'down') ? $r* $cols : ($rows- 1- $r)* $cols;
for ($c= 0; $c< $cols; $c++ ) {
$x = ($hdir == 'right') ? $rx+ $c : $rx+ $cols- 1- $c;
/* shuffle x to loop over rows*/
$x = floor($x/ $cols) + ($x% $cols)* $rows;
$ret = $var[$no % count($var)];
return ($ret) ? ' '. $ret : '';
/* vim: set expandtab: */
|