Get Smarty

Donate

Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Advertisement

{html_table}

{html_table} は、HTML の <table> にデータの配列を出力する カスタム関数 です。

属性名 必須 デフォルト 概要
loop array Yes n/a ループに用いるデータ配列
cols mixed No 3 テーブルのカラム数。cols属性は空であるがrows属性が与えられたという場合、 colsの数は、すべての要素を表示するのに事足りるcolsが表示されるように rowsの数と要素の数によって計算されます。 rowsとcolsの両方が空だった場合、 colsのデフォルトは 3 として計算は省かれます。 リストあるいは配列を渡すと、そのリストあるいは配列の要素数がカラム数となります。
rows integer No empty テーブルの行数。rows属性は空であるがcols属性が与えられたという場合、 rowsの数は、すべての要素を表示するのに事足りるrowsが表示されるように colsの数と要素の数によって計算されます。
inner string No cols ループ配列から参照される連続要素の進行方向。 cols なら要素が列方向へ、 rows なら要素が行方向へ記述されることを意味します。
caption string No empty テーブルの <caption> 要素に使用する文字列
table_attr string No border="1" <table> タグの属性
th_attr string No empty <th> タグの属性 (配列は循環します)
tr_attr string No empty <tr> タグの属性 (配列は循環します)
td_attr string No empty <td> タグの属性 (配列は循環します)
trailpad string No &nbsp; 行の最後に余ったセルがあればそれらを埋めるのに用いられる値
hdir string No right 各行の表示される方向。有効な値: right (左から右へ)、 left (右から左へ)
vdir string No down 各カラムの表示される方向。有効な値: down (上から下へ)、 up (下から上へ)
  • cols 属性は、テーブルのカラム数を定義します。

  • table_attrtr_attr および td_attr の値は、それぞれ <table><tr> および <td> タグの属性を表します。

  • tr_attrtd_attr が配列の場合は、循環して処理します。

  • trailpad は、テーブルの最後の行でセルが余った場合に そこを埋める値として使用します。

Example 8.19. {html_table}


<?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');
?>

  

PHP から割り当てられた変数の内容を、三通りの方法で出力します。 それぞれ、テンプレートの後に出力結果を続けます。


{**** 例 1 ****}
{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>


{**** 例 2 ****}
{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>


{**** 例 3 ****}
{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>

  

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors