一、塊函數(foreach/ if / elseif)php
(1)hanshu.phphtml
<?php require "DBDA.class.php"; require "../init.inc.php"; $db = new DBDA(); $sql = "select * from users"; $arr = $db->query($sql); $smarty->assign("shuju",$arr); $smarty->display("hanshu.html"); ?>
(2).hanshu.html (foreach 遍歷)sql
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <table width="100%" border="1px" cellpadding="0px" cellspacing="0px"> <tr> <td>用戶名</td> <td>密碼</td> <td>姓名</td> <td>性別</td> <td>生日</td> </tr> <{foreach $shuju as $v}> <tr> <td><{$v[0]}></td> <td><{$v[1]}></td> <td><{$v[2]}></td> <td><{$v[3]}></td> <td><{$v[4]}></td> </tr> <{/foreach}> </table> </body> </html>
效果圖:函數
hanshu.html (if 判斷 將上圖中性別 改成男女)ui
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <table width="100%" border="1px" cellpadding="0px" cellspacing="0px"> <tr> <td>用戶名</td> <td>密碼</td> <td>姓名</td> <td>性別</td> <td>生日</td> </tr> <{foreach $shuju as $v}> <tr> <td><{$v[0]}></td> <td><{$v[1]}></td> <td><{$v[2]}></td> <td> <{if $v[3] }>男 <{else}>女 <{/if}> </td> <td><{$v[4]}></td> </tr> <{/foreach}> </table> </body> </html>
效果圖:spa
一、<{literal}><{/literal}>:當代碼放於其中時,代碼不會被解析3d
二、{html_select_date month_format="%m"}>code
三、<{date name="date"}> 必須有nameorm
四、<{color name="color"}>htm
五、<{textarea name="textarea" toolbar="full" color="red"}> <{/textarea}>