2014-01-26 79 views
1

我想每行顯示3個圖像。但代碼顯示第一行2(2)圖像,然後顯示下一行3圖像。代碼的問題在哪裏?每行顯示3個圖像

<table style="width: 99%;padding-top:30px;" dir="ltr" border="0" cellspacing="0" cellpadding="0"> 
      <tbody> 


       <tr> 
       {foreach from=$execommittee item=v name=cat} 

       {if $smarty.foreach.cat.iteration % 3 == 0 && $smarty.foreach.cat.iteration > 0} 

       </tr> 
       <tr> 

       {/if} 
       <td width="142"> 
       <p style="text-align: center;" align="justify"> 
       <img src="themes/{$themes}/resources/images/publications/{$v.efilename}" border="0" width="142" height="152" /></a></p> 
       <p style="text-align: center;" align="justify">{$v.ename}</p> 
       </td> 

       {/foreach} 
      </tr> 

      </tbody> 
      </table> 
+0

'$ smarty.foreach.cat.iteration'總是會大於0,因爲它開始於1(http://www.smarty.net/docsv2/en/language.function.foreach.tpl#foreach。 property.iteration),所以你不需要在你的'if'語句中有這個。 – guessimtoolate

回答

3
<table style="width: 99%;padding-top:30px;" dir="ltr" border="0" cellspacing="0" cellpadding="0"> 
      <tbody> 



       {foreach from=$execommittee item=v name=cat} 
       <tr> 
       {if $smarty.foreach.cat.iteration % 3 == 0 && $smarty.foreach.cat.iteration > 0} 

       </tr> 
       <tr> 

       {/if} 
       <td width="142"> 
       <p style="text-align: center;" align="justify"> 
       <img src="themes/{$themes}/resources/images/publications/{$v.efilename}" border="0" width="142" height="152" /></a></p> 
       <p style="text-align: center;" align="justify">{$v.ename}</p> 
        </td> 
       </tr> 
       {/foreach} 


      </tbody> 
      </table> 

您的TR標籤應該是你的循環中。我不確定如果陳述,我認爲它不需要。

+0

您的代碼每行顯示一個圖像。 – prasun