<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>{html_table}</title> <meta name="generator" content="DocBook XSL Stylesheets V1.75.1"> <link rel="home" href="index.html" title="Smarty Manual"> <link rel="up" href="language.custom.functions.html" title="Chapter 8. Custom Functions"> <link rel="prev" href="language.function.html.select.time.html" title="{html_select_time}"> <link rel="next" href="language.function.mailto.html" title="{mailto}"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">{html_table}</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="language.function.html.select.time.html">Prev</a> </td> <th width="60%" align="center">Chapter 8. Custom Functions</th> <td width="20%" align="right"> <a accesskey="n" href="language.function.mailto.html">Next</a> </td> </tr> </table> <hr> </div> <div class="sect1" title="{html_table}"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="language.function.html.table"></a>{html_table}</h2></div></div></div> <p> <code class="varname">{html_table}</code> is a <a class="link" href="language.custom.functions.html" title="Chapter 8. Custom Functions">custom function</a> that dumps an array of data into an HTML <code class="literal"><table></code>. </p> <div class="informaltable"><table border="1"> <colgroup> <col align="center"> <col align="center"> <col align="center"> <col align="center"> <col> </colgroup> <thead><tr> <th align="center">Attribute Name</th> <th align="center">Type</th> <th align="center">Required</th> <th align="center">Default</th> <th>Description</th> </tr></thead> <tbody> <tr> <td align="center">loop</td> <td align="center">array</td> <td align="center">Yes</td> <td align="center"><span class="emphasis"><em>n/a</em></span></td> <td>Array of data to loop through</td> </tr> <tr> <td align="center">cols</td> <td align="center">mixed</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>3</em></span></td> <td> 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. </td> </tr> <tr> <td align="center">rows</td> <td align="center">integer</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>empty</em></span></td> <td> 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. </td> </tr> <tr> <td align="center">inner</td> <td align="center">string</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>cols</em></span></td> <td> Direction of consecutive elements in the loop-array to be rendered. <span class="emphasis"><em>cols</em></span> means elements are displayed col-by-col. <span class="emphasis"><em>rows</em></span> means elements are displayed row-by-row. </td> </tr> <tr> <td align="center">caption</td> <td align="center">string</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>empty</em></span></td> <td>Text to be used for the <code class="literal"><caption></code> element of the table</td> </tr> <tr> <td align="center">table_attr</td> <td align="center">string</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>border="1"</em></span></td> <td>Attributes for <code class="literal"><table></code> tag</td> </tr> <tr> <td align="center">th_attr</td> <td align="center">string</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>empty</em></span></td> <td>Attributes for <code class="literal"><th></code> tag (arrays are cycled)</td> </tr> <tr> <td align="center">tr_attr</td> <td align="center">string</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>empty</em></span></td> <td>attributes for <code class="literal"><tr></code> tag (arrays are cycled)</td> </tr> <tr> <td align="center">td_attr</td> <td align="center">string</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>empty</em></span></td> <td>Attributes for <code class="literal"><td></code> tag (arrays are cycled)</td> </tr> <tr> <td align="center">trailpad</td> <td align="center">string</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>&nbsp;</em></span></td> <td>Value to pad the trailing cells on last row with (if any)</td> </tr> <tr> <td align="center">hdir</td> <td align="center">string</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>right</em></span></td> <td> Direction of each row to be rendered. possible values: <span class="emphasis"><em>right</em></span> (left-to-right), and <span class="emphasis"><em>left</em></span> (right-to-left) </td> </tr> <tr> <td align="center">vdir</td> <td align="center">string</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>down</em></span></td> <td> Direction of each column to be rendered. possible values: <span class="emphasis"><em>down</em></span> (top-to-bottom), <span class="emphasis"><em>up</em></span> (bottom-to-top) </td> </tr> </tbody> </table></div> <div class="itemizedlist"><ul class="itemizedlist" type="disc"> <li class="listitem"><p> The <em class="parameter"><code>cols</code></em> attribute determines how many columns will be in the table. </p></li> <li class="listitem"><p> The <em class="parameter"><code>table_attr</code></em>, <em class="parameter"><code>tr_attr</code></em> and <em class="parameter"><code>td_attr</code></em> values determine the attributes given to the <code class="literal"><table></code>, <code class="literal"><tr></code> and <code class="literal"><td></code> tags. </p></li> <li class="listitem"><p> If <em class="parameter"><code>tr_attr</code></em> or <em class="parameter"><code>td_attr</code></em> are arrays, they will be cycled through. </p></li> <li class="listitem"><p> <em class="parameter"><code>trailpad</code></em> is the value put into the trailing cells on the last table row if there are any present. </p></li> </ul></div> <div class="example"> <a name="id3074875"></a><p class="title"><b>Example 8.22. {html_table}</b></p> <div class="example-contents"> <pre class="programlisting"> <?php $smarty->assign( 'data', array(1,2,3,4,5,6,7,8,9) ); $smarty->assign( 'tr', array('bgcolor="#eeeeee"','bgcolor="#dddddd"') ); $smarty->display('index.tpl'); ?> </pre> <p>The variables assigned from php could be displayed as these three examples demonstrate. Each example shows the template followed by output. </p> <pre class="programlisting"> {**** Example One ****} {html_table loop=$data} <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> {**** Example Two ****} {html_table loop=$data cols=4 table_attr='border="0"'} <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> {**** Example Three ****} {html_table loop=$data cols="first,second,third,fourth" tr_attr=$tr} <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> </pre> </div> </div> <br class="example-break"> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="language.function.html.select.time.html">Prev</a> </td> <td width="20%" align="center"><a accesskey="u" href="language.custom.functions.html">Up</a></td> <td width="40%" align="right"> <a accesskey="n" href="language.function.mailto.html">Next</a> </td> </tr> <tr> <td width="40%" align="left" valign="top">{html_select_time} </td> <td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td> <td width="40%" align="right" valign="top"> {mailto}</td> </tr> </table> </div> </body> </html>