- 论坛徽章:
- 0
|
Qiao老大翻译有些错误。官方的错误。
[quote]原帖由 HonestQiao 于 2005-8-15 15:01 发表
SmartTemplate::append()
void append ( string PLACEHOLDER, mixed CONTENT )
追加内容给模板占位符. 可以使用散列数组或者标量.
例子1 (列表):
- < ... [/quote]
- append的使用正确方式是这样的,=>应该为,
- [code]$page->append('userlist',array('ID=>123','NAME'=>'Joyen'));
复制代码
加上include的流程控制
As of version 1.2.0 templates can be included in other templates by using the INCLUDE statement.
This permit the use of subtemplating.
The syntax is the following: <!– INCLUDE templatename.html –>
include.php:
- require_once "class.smarttemplate.php";
- $page = new SmartTemplate("begin_end.html");
-
- $users = array(
- array( 'NAME' => 'John Doe', 'GROUP' => 'ADMIN' ),
- array( 'NAME' => 'Jack Doe', 'GROUP' => 'SUPPORT' ),
- array( 'NAME' => 'James Doe', 'GROUP' => 'GUEST' ),
- array( 'NAME' => 'Jane Doe', 'GROUP' => 'GUEST' ),
- );
-
- $page->assign( 'users', $users );
-
- $page->output();
复制代码
The HTML Template that is used by the PHP Script is displayed in the following box:
begin_end.html:
- <style type="text/css">
- .col0 { background-color: #D0D0D0; }
- .col1 { background-color: #F0F0F0; }
- </style>
-
- <table border="1" cellpadding="2" cellspacing="0">
- <tr>
- <th> No </th>
- <th> Username </th>
- <th> Usergroup </th>
- </tr>
-
- <!-- BEGIN users -->
-
- <tr class="col{ROWBIT}">
- <td> {ROWCNT} </td>
- <td> {NAME} </td>
- <td> {GROUP} </td>
- </tr>
-
- <!-- END users -->
-
- </table>
复制代码
The Result that is created by the PHP Script is displayed in the following box:
Ouput:
- <style type="text/css">
- .col0 { background-color: #D0D0D0; }
- .col1 { background-color: #F0F0F0; }
- </style>
-
- <table border="1" cellpadding="2" cellspacing="0">
- <tr>
- <th> No </th>
- <th> Username </th>
- <th> Usergroup </th>
- </tr>
-
-
- <tr class="col0">
- <td> 0 </td>
- <td> John Doe </td>
- <td> ADMIN </td>
- </tr>
-
-
- <tr class="col1">
- <td> 1 </td>
- <td> Jack Doe </td>
- <td> SUPPORT </td>
- </tr>
-
-
- <tr class="col0">
- <td> 2 </td>
- <td> James Doe </td>
- <td> GUEST </td>
- </tr>
-
-
- <tr class="col1">
- <td> 3 </td>
- <td> Jane Doe </td>
- <td> GUEST </td>
- </tr>
-
-
- </table>
复制代码 |
|