推荐于2016-08-24
展开全部
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 已经assign一个模版变量 $assign ,由于要做特殊的循环输出,使用 for 循环,因此使用到了php标签,但是php语句和模版语句的变量作用域是不同的,因此不能直接获取到 {{php}} for ( $i =0; $i < count ( $assign ); $i = $i +2){ echo ' <ul> <li> <span class = "zz_pic" ><a href= "'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i][pic_id])).'" title= "" ><img src= "uploads/thumb_'.$assign[$i][pic].'" alt= "" ></a></span> <span class = "zz_title" ><a href= "'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i][pic_id])).'" title= "" > '.$assign[$i][title].' </a></span> </li> <li> <span class = "zz_pic" ><a href= "'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i+1][pic_id])).'" title= "" ><img src= "uploads/thumb_'.$assign[$i+1][pic].'" alt= "" ></a></span> <span class = "zz_title" ><a href= "'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i+1][pic_id])).'" title= "" > '.$assign[$i+1][title].' </a></span> </li>i> </ul>';} {{/php}} 解决的方法是:模版变量全部存在smarty的一个对象里面;只要在 for 之前进行赋值: $assign = $this ->_tpl_vars[assign]; {{php}} $assign = $this ->_tpl_vars[assign]; for ( $i =0; $i < count ( $assign ); $i = $i +2){ echo ' <ul> <li> <span class = "zz_pic" ><a href= "'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i][pic_id])).'" title= "" ><img src= "uploads/thumb_'.$assign[$i][pic].'" alt= "" ></a></span> <span class = "zz_title" ><a href= "'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i][pic_id])).'" title= "" > '.$assign[$i][title].' </a></span> </li> <li> <span class = "zz_pic" ><a href= "'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i+1][pic_id])).'" title= "" ><img src= "uploads/thumb_'.$assign[$i+1][pic].'" alt= "" ></a></span> <span class = "zz_title" ><a href= "'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i+1][pic_id])).'" title= "" > '.$assign[$i+1][title].' </a></span> </li>i> </ul>';} {{/php}} |
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询