锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
1銆丼martTemplate鐨勬晥鐜?
2銆佸熀鏈彉閲?
3銆侀昏緫榪愮畻緇撴瀯
4銆佹ā寮忥紙Methods錛?
5銆佹墿灞曠被(Extensions) 鏈畬鎴?
------------------------------------------------------------------------
1銆丼martTemplate鐨勬晥鐜?
铏界劧浠栨湁寰堝鐨勭▼搴忔潵褰㈡垚寮哄ぇ鐨勫姛鑳斤紝浣嗗湪鎵ц鏃跺彧鏈変綘璋冪敤鐨勬墠琚鍏ワ紝鎵浠ヤ笉鐢ㄦ媴蹇冭繖鏂歸潰鐨勯熷害褰卞搷錛屽悓鏍瘋繖濂楁ā鐗堢郴緇熸槸涓烘渶蹇殑鎵ц鏁堢巼鑰屼紭鍖栬繃鐨勶紝姣旇搗鐩墠甯傚満涓婂父瑙佺殑Smarty錛岃蹇笉灝戯紙Smarty閲囩敤鍚庢湡緙撳瓨錛屾墍浠ユ瘮杈冨彲鑳戒笉鏄緢鍑嗙‘錛夈?
2銆丼martTemplate鐨勫彉閲?
Array鐨勫彉閲忔槸鐢盨martTemplate鍐呭緩鍑芥暟assign錛堬級鏉ヨ祴鍊肩殑
鍏蜂綋璇硶濡備笅
code: assign ( 妯$増涓殑鍙橀噺, 瑕佹浛鎹㈢殑鍐呭 ) |
code: assign ( Array鍐呭 ) |
code: <?php $template = new SmartTemplate('template.html'); $text = 'Sample Text'; $template->assign( 'TITLE', $text ); $template->output(); ?> |
code: <html> {TITLE} </html> |
code: <html> Sample Text </html> |
code: <?php $user = array( 'NAME' => 'John Doe', 'GROUP' => 'Admin', 'AGE' => '42', ); $template = new SmartTemplate('user.html'); $template->assign( $user ); $template->output(); ?> |
code: Name: {NAME} Group: {GROUP} Age: {AGE} 杈撳嚭 CODE Name: John Doe Group: Admin Age: 42 |
涓嬮潰鏄彟澶栦竴涓緥瀛愩備嬌鐢ㄤ簡SmartTemplate鐨勫驚鐜嚱鏁?lt;!-- begin Array鍚?-->XXXXXX<!-- end Array鍚?gt;
浠栫殑鍔熻兘綾諱技foreach()錛屽彧瑕佹湁涓滆タ錛屽氨涓鐩村驚鐜樉紺?
code: <?php $links = array( array( 'TITLE' => 'PHP', 'URL' => 'http://www.php.net/', ), array( 'TITLE' => 'Apache', 'URL' => 'http://www.php.net/', ), array( 'TITLE' => 'MySQL', 'URL' => 'http://www.mysql.com/', ), ); $template = new SmartTemplate('links.html'); $template->assign( 'links', $links ); $template->output(); ?> |
code: <html> <h3> Sample Links </h3> <!-- BEGIN links --> <a href="../{URL}"> {TITLE} </a> <!-- END links --> </html> CODE <html> <h3> Sample Links </h3> <a href="../ <a href="../ <a href="../</html> |
code: <?php require_once "class.smarttemplate.php"; $page = new SmartTemplate("if.html"); $page->assign( 'username', 'John Doe' ); $page->assign( 'usergroup', 'ADMIN' ); $page->assign( 'picture', '' ); $page->output(); ?> |
code: <!-- IF username --> <H3> Welcome, {username} </H3> <!-- ENDIF --> <!-- IF picture --> <img src="{picture}"> <!-- ENDIF picture --> <!-- IF usergroup="ADMIN" --> <a href="../admin.php"> ADMIN Login </a><br> <!-- ENDIF usergroup --> |
code: <H3> Welcome, John Doe </H3> <a href="../admin.php"> ADMIN Login </a><br> |
code: <?php require_once "class.smarttemplate.php"; $page = new SmartTemplate("else.html"); $page->assign( 'username', 'John Doe' ); $page->assign( 'usergroup', 'ADMIN' ); $page->assign( 'picture', '' ); $page->output(); ?> |
code: <!-- IF username --> <H3> Welcome, {username} </H3> <!-- ENDIF --> <!-- IF picture --> <img src="{picture}"> <!-- ELSE --> Picture not available! <br> <!-- ENDIF picture --> <!-- IF usergroup="ADMIN" --> <a href="../admin.php"> ADMIN Login </a><br> <!-- ELSE --> You are in guest mode! <!-- ENDIF usergroup --> |
code: <H3> Welcome, John Doe </H3> Picture not available! <br> <a href="../admin.php"> ADMIN Login </a><br> |
code: <?php require_once "class.smarttemplate.php"; $page = new SmartTemplate("elseif.html"); $page->assign( 'usergroup', 'INTERNAL' ); $page->output(); ?> |
code: <!-- IF usergroup="ADMIN" --> <a href="../admin.php"> 綆$悊鍛樼櫥闄?</a><br> <!-- ELSEIF usergroup="SUPPORT" --> <a href="../support.php"> 甯姪浜哄憳鐧婚檰</a><br> <!-- ELSEIF usergroup --> <a href="../other.php"> 鏅氭柟寮忕櫥闄?</a><br> <!-- ELSE --> You don't even have a usergroup! <!-- ENDIF --> |
code: <a href="../other.php"> 鏅氭柟寮忕櫥闄?</a><br> |
code: <?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(); ?> |
code: <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> |
code: <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> |
code: <?php $page = new SmartTemplate('links.html'); $page->append('links' => array( 'TITLE' => 'PHP', 'URL' => 'http://www.php.net/' )); $page->append('links' => array( 'TITLE' => 'Apache', 'URL' => 'http://www.apache.org/' )); $page->append('links' => array( 'TITLE' => 'MySQL', 'URL' => 'http://www.mysql.com/' )); $page->output(); ?> |
code: <html> <h3> Sample Links </h3> <!-- BEGIN links --> <a href="../{URL}"> {TITLE} </a> <!-- END links --> </html> |
code: <html> <h3> Sample Links </h3> <a href="../http://www.php.net/"> PHP </a> <a href="../http://www.apache.org/"> Apache </a> <a href="../http://www.mysql.com/"> MySQL </a> </html> |
code: <?php $page = new SmartTemplate('template.html'); $page->append('TITLE' => 'Hello '); $page->append('TITLE' => 'World '); $page->append('TITLE' => '!'); $page->output(); ?> |
code: