已經(jīng)assign一個(gè)模版變量$assign,由于要做特殊的循環(huán)輸出,使用for循環(huán),因此使用到了php標(biāo)簽,但是php語(yǔ)句和模版語(yǔ)句的變量作用域是不同的,因此不能直接獲取到
{{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的一個(gè)對(duì)象里面;只要在for之前進(jìn)行賦值:$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}}