Files
smarty/docs/en/designers/language-custom-functions/language-function-html-table.xml

251 lines
7.2 KiB
XML
Raw Normal View History

2004-04-13 08:46:28 +00:00
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<sect1 id="language.function.html.table">
<title>{html_table}</title>
2005-09-13 19:03:11 +00:00
<para>
<varname>{html_table}</varname> is a
2005-09-13 19:03:11 +00:00
<link linkend="language.custom.functions">custom function</link>
that dumps an array of data into an HTML <literal>&lt;table&gt;</literal>.
</para>
<informaltable frame="all">
<tgroup cols="5">
<colspec colname="param" align="center" />
<colspec colname="type" align="center" />
<colspec colname="required" align="center" />
<colspec colname="default" align="center" />
<colspec colname="desc" />
<thead>
<row>
<entry>Attribute Name</entry>
<entry>Type</entry>
<entry>Required</entry>
<entry>Default</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>loop</entry>
<entry>array</entry>
<entry>Yes</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>Array of data to loop through</entry>
</row>
<row>
<entry>cols</entry>
<entry>mixed</entry>
<entry>No</entry>
<entry><emphasis>3</emphasis></entry>
<entry>
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. 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>
<entry>rows</entry>
<entry>integer</entry>
<entry>No</entry>
<entry><emphasis>empty</emphasis></entry>
<entry>
Number of rows in the table. if the rows-attribute is empty, but
cols are given, then the number of rows is computed by the number of
cols and the number of elements to display to be just enough rows to
display all elements.
</entry>
</row>
<row>
<entry>inner</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>cols</emphasis></entry>
<entry>
Direction of consecutive elements in the loop-array to be
rendered. <emphasis>cols</emphasis> means elements are displayed
col-by-col. <emphasis>rows</emphasis> means elements are displayed
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 <literal>&lt;caption&gt;</literal>
element of the table</entry>
</row>
<row>
<entry>table_attr</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>border="1"</emphasis></entry>
<entry>Attributes for <literal>&lt;table&gt;</literal> tag</entry>
</row>
<row>
<entry>th_attr</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>empty</emphasis></entry>
<entry>Attributes for <literal>&lt;th&gt;</literal> tag
(arrays are cycled)</entry>
</row>
<row>
<entry>tr_attr</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>empty</emphasis></entry>
<entry>attributes for <literal>&lt;tr&gt;</literal> tag
(arrays are cycled)</entry>
</row>
<row>
<entry>td_attr</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>empty</emphasis></entry>
<entry>Attributes for <literal>&lt;td&gt;</literal> tag
(arrays are cycled)</entry>
</row>
<row>
<entry>trailpad</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>&amp;nbsp;</emphasis></entry>
<entry>Value to pad the trailing cells on last row with (if any)</entry>
</row>
<row>
<entry>hdir</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>right</emphasis></entry>
<entry>
Direction of each row to be rendered. possible values:
2005-09-14 16:01:38 +00:00
<emphasis>right</emphasis> (left-to-right), and
<emphasis>left</emphasis> (right-to-left)
</entry>
</row>
<row>
<entry>vdir</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>down</emphasis></entry>
<entry>
Direction of each column to be rendered. possible values:
<emphasis>down</emphasis> (top-to-bottom), <emphasis>up</emphasis>
(bottom-to-top)
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
2005-09-13 19:03:11 +00:00
<itemizedlist>
<listitem><para>
The <parameter>cols</parameter> attribute determines how many
columns will be in the table.
</para></listitem>
<listitem><para>
The <parameter>table_attr</parameter>, <parameter>tr_attr</parameter>
and <parameter>td_attr</parameter> values determine the attributes given
to the <literal>&lt;table&gt;</literal>, <literal>&lt;tr&gt;</literal>
and <literal>&lt;td&gt;</literal> tags.
</para></listitem>
<listitem><para>
If <parameter>tr_attr</parameter> or <parameter>td_attr</parameter> are
arrays, they will be cycled through.
</para></listitem>
<listitem><para>
<parameter>trailpad</parameter> is the value put into the trailing cells
on the last table row if there are any present.
</para></listitem>
</itemizedlist>
<example>
<title>{html_table}</title>
<programlisting role="php">
2004-04-13 08:46:28 +00:00
<![CDATA[
<?php
$smarty->assign( 'data', array(1,2,3,4,5,6,7,8,9) );
$smarty->assign( 'tr', array('bgcolor="#eeeeee"','bgcolor="#dddddd"') );
2004-04-13 08:46:28 +00:00
$smarty->display('index.tpl');
?>
]]>
</programlisting>
<para>The variables assigned from php could be displayed as these three
examples demonstrate. Each example shows the template followed by output.
</para>
<programlisting>
<![CDATA[
{**** Example One ****}
2004-04-13 08:46:28 +00:00
{html_table loop=$data}
2004-04-13 08:46:28 +00:00
<table border="1">
<tbody>
2004-04-13 08:46:28 +00:00
<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>
2004-04-13 08:46:28 +00:00
</table>
{**** Example Two ****}
{html_table loop=$data cols=4 table_attr='border="0"'}
2004-04-13 08:46:28 +00:00
<table border="0">
<tbody>
2004-04-13 08:46:28 +00:00
<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>
2004-04-13 08:46:28 +00:00
</table>
{**** Example Three ****}
{html_table loop=$data cols="first,second,third,fourth" tr_attr=$tr}
2004-04-13 08:46:28 +00:00
<table border="1">
<thead>
<tr>
<th>first</th><th>second</th><th>third</th><th>fourth</th>
</tr>
</thead>
<tbody>
2004-04-13 08:46:28 +00:00
<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>
2004-04-13 08:46:28 +00:00
</table>
]]>
</programlisting>
</example>
2004-04-13 08:46:28 +00:00
</sect1>
2004-04-13 08:46:28 +00:00
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->