萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> php中smarty模板條件判斷用法實例

php中smarty模板條件判斷用法實例

 模板文件test6.html代碼:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 <html> <head> <title>Smarty Test</title> </head> <body> <table width="200" border="0"> {if $cond == 1} <tr> <td>條件成立</td> </tr> {else} <tr> <td>條件不成立</td> </tr> {/if} </table> </body> </html>

php代碼:

1 2 3 4 5 6 7 <?php require 'libs/Smarty.class.php'; //包含Smarty類庫文件 $smarty = new Smarty; //創建一個新的Smarty對象 $cond = 1; $smarty->assign("cond",$cond); //對模版中的變量賦值 $smarty->display('test6.htm'); //顯示頁面 ?>
copyright © 萬盛學電腦網 all rights reserved