smarty foreach 实现自动生成多行多列table

效果图

 html

 <tr>                    
    <td><label for="" class="control-label">支持协议:</label></td> 
    <td><input type="text"   class='my_input' name="agreement" id="agreement"  /> </td>                    
    <td><label for="" class="control-label">外观颜色:</label></td> 
    <td><select name="appearance_color" id="appearance_color"  class="easyui-combobox" style="height:28px;width:160px;" editable=false ><option value='蓝色'>蓝色</option>
        <option value='红色'>红色</option>
        <option value='白色'>白色</option>
     </select> 
</td>
</tr> <tr> <td><label for="" class="control-label">上市时间:</label></td> <td><input type="text" class='my_input laydate-icon' style='height:29px;' onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" readonly value="1970-01-01 07:33:42" name="market_time" id="market_time" /> </td> <td><label for="" class="control-label">产品等级:</label></td> <td><select name="grade" id="grade" class="easyui-combobox" style="height:28px;width:160px;" editable=false ><option value='普通款'>普通款</option>         <option value='一级品'>一级品</option>         <option value='特级品'>特级品</option>      </select>
</td> </tr> <tr> <td><label for="" class="control-label">支持接口:</label></td> <td><select name="interface" id="interface" class="easyui-combobox" style="height:28px;width:160px;" editable=false >
<option value='Type-C'>Type-C</option>        <option value='Usb'>Usb</option> </select>
</td> </tr>
smarty 代码
<{foreach $items as $r name=row_name }>
                    
    <{if $smarty.foreach.row_name.index%2==0}>            
        <tr>
   <{/if}>
                        
     <td><label for="<{$r['id']}>" class="control-label"><{$r['field_display_name']}>:</label></td> 
      <td><{$r['html']}> </td>  
                      
   <{if $smarty.foreach.row_name.index%2!=0}>
       </tr>
   <{else}>
       <{if $smarty.foreach.row_name.last==true}>
           </tr>
       <{/if}>
   <{/if}>
<{/foreach}> 

其中

$smarty.foreach.row_name.index%2==0   偶数行
$smarty.foreach.row_name.index%2!=0   奇数行
$smarty.foreach.row_name.last==true   最后一行

php代码

$smarty->assign('items',$forms);  

 

posted @ 2022-06-09 22:14  海乐学习  阅读(51)  评论(0编辑  收藏  举报