php学习 之 Smarty 逻辑判断 和 循环

来源:互联网 发布:fp6601q数据手册 编辑:程序博客网 时间:2024/06/05 19:10
1 if...else  和 for

{for $i=$start to 100 step 2}{if $i@first||$i@last}<font color='red'>{$i}</font>{else}{$i}{/if}{/for}

我自己的翻译是

(Smarty本身的翻译要一大堆)//自己可以看smarty生成的模板源码

for($i=$start;$i<100;$i+=2){  if($i==$start ||$i==99)  {     echo "<font color='red'>".$i.'</font>';  }  else  {     echo $i;  }}


注意

在使用 Smarty标签的时候,不要类似 { if } 这样的有空格,最好{if} 前后都不要空格,当然后面有空格没有关系,但是if前面有空格就会解析错误

<table border=1 cellspacing=0 cellpadding=10><tr><th>序号</th><th>商品名</th><th>价格</th><th>发布时间</th></tr>{foreach $arr as $k => $v}{if $v@iteration%2}<tr>{else}<tr bgcolor=#eee>{/if}<td>{$v.goods_id}</td><td>{$v.goods_name}</td><td>{$v.shop_price}</td><td>{$v.add_time|date_format:'Y年m月d日 H:i:s'}</td></tr>{/foreach}</table>


原创粉丝点击