本文實例講述了php中smarty模板條件判斷用法。分享給大家供大家參考。具體實現方法如下:
模板文件test6.html代碼:
<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代碼:
<?php
require 'libs/Smarty.class.php'; //包含Smarty類庫文件
$smarty = new Smarty; //創建一個新的Smarty對象
$cond = 1;
$smarty->assign("cond",$cond); //對模版中的變量賦值
$smarty->display('test6.htm'); //顯示頁面
?>
希望本文所述對大家的php程序設計有所幫助。