怎么在php中使用smarty模板条件判断

这篇文章将为大家详细讲解有关怎么在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中使用smarty模板条件判断就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。