html_table: fixed th/tr output, added hdir support for column headings,update docs to reflect new features

This commit is contained in:
boots
2006-07-10 15:37:08 +00:00
parent bc1451baf7
commit da6df3c7f1
3 changed files with 43 additions and 8 deletions

2
NEWS
View File

@@ -1,3 +1,5 @@
- added support for column headings and caption element to html_table and
updated the output to use thead/tbody elements (boots)
- fixed ordering of replacements in trimwhitespace output filter (Getty, boots)
- update mailto function plugin to work around a firefox/thunderbird
escaping bug (elijahlofgren, boots)

View File

@@ -41,15 +41,17 @@
</row>
<row>
<entry>cols</entry>
<entry>integer</entry>
<entry>mixed</entry>
<entry>No</entry>
<entry><emphasis>3</emphasis></entry>
<entry>
number of columns in the table. if the cols-attribute is empty,
number of columns in the table or a comma-separated list of column heading
names or an array of column heading names.if the cols-attribute is empty,
but rows are given, then the number of cols is computed by the number
of rows and the number of elements to display to be just enough cols to
display all elements. If both, rows and cols, are omitted cols defaults
to 3.
to 3. if given as a list or array, the number of columns is computed from
the number of elements in the list or array.
</entry>
</row>
<row>
@@ -76,6 +78,15 @@
row-by-row.
</entry>
</row>
<row>
<entry>caption</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>empty</emphasis></entry>
<entry>
text to be used for the caption element of the table.
</entry>
</row>
<row>
<entry>table_attr</entry>
<entry>string</entry>
@@ -83,6 +94,13 @@
<entry><emphasis>border="1"</emphasis></entry>
<entry>attributes for table tag</entry>
</row>
<row>
<entry>th_attr</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>empty</emphasis></entry>
<entry>attributes for th tag (arrays are cycled)</entry>
</row>
<row>
<entry>tr_attr</entry>
<entry>string</entry>
@@ -152,7 +170,7 @@ template code:
--------------
{html_table loop=$data}
{html_table loop=$data cols=4 table_attr='border="0"'}
{html_table loop=$data cols=4 tr_attr=$tr}
{html_table loop=$data cols="first,second,third,fourth" tr_attr=$tr}
]]>
</programlisting>
<para>
@@ -161,19 +179,30 @@ template code:
<screen>
<![CDATA[
<table border="1">
<tbody>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>4</td><td>5</td><td>6</td></tr>
<tr><td>7</td><td>8</td><td>9</td></tr>
</tbody>
</table>
<table border="0">
<tbody>
<tr><td>1</td><td>2</td><td>3</td><td>4</td></tr>
<tr><td>5</td><td>6</td><td>7</td><td>8</td></tr>
<tr><td>9</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
</tbody>
</table>
<table border="1">
<thead>
<tr>
<th>first</th><th>second</th><th>third</th><th>fourth</th>
</tr>
</thead>
<tbody>
<tr bgcolor="#eeeeee"><td>1</td><td>2</td><td>3</td><td>4</td></tr>
<tr bgcolor="#dddddd"><td>5</td><td>6</td><td>7</td><td>8</td></tr>
<tr bgcolor="#eeeeee"><td>9</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
</tbody>
</table>
]]>
</screen>

View File

@@ -34,10 +34,12 @@
* <pre>
* {table loop=$data}
* {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
* {table loop=$data cols=4 tr_attr=$colors}
* {table loop=$data cols="first,second,third" tr_attr=$colors}
* </pre>
* @author Monte Ohrt <monte at ohrt dot com>
* @version 1.0
* @author credit to Messju Mohr <messju at lammfellpuschen dot de>
* @author credit to boots <smarty dot boots at yahoo dot com>
* @version 1.1
* @link http://smarty.php.net/manual/en/language.function.html.table.php {html_table}
* (Smarty online manual)
* @param array
@@ -122,13 +124,15 @@ function smarty_function_html_table($params, &$smarty)
}
if (is_array($cols)) {
$cols = ($hdir == 'right') ? $cols : array_reverse($cols);
$output .= "<thead><tr>\n";
for ($r=0; $r<$cols_count; $r++) {
$output .= '<th' . smarty_function_html_table_cycle('th', $th_attr, $r) . '>';
$output .= $cols[$r];
$output .= "</tr></th>\n";
$output .= "</th>\n";
}
$output .= "</thead>\n";
$output .= "</tr></thead>\n";
}
$output .= "<tbody>\n";