做一个三维数组吧,可以用section通过双重循环实现。

解决方案 »

  1.   

    变量处理一下,用数组很方便啊
    没什么局限不局限得$array = array(1,2,3,4,5,6,7);
    $i=0;
    $new_array = array();
    for($i=0;$i<count($array);$i++)
    {
     $new_array[$i][] = $array[$i];
     $new_array[$i][] = $array[++$i];
    }
      

  2.   

    用section可以很简单的解决:
    在tpl中,
    <tr> 
    <section name=ImageID loop=$ImageList>
        <td width="100">{$ImageList[ImageID].ImageName}</td>
        {if $smarty.section.ImageID.rownum is div by 2}
        </tr>
        <tr>
        {/if}
    </section>
    </tr>$ImageList数组必须从0开始。
      

  3.   

    你好,我是
    <tr>
    <%section name=ImageID loop=$ImageList%>
        <td width="100">{$ImageList[ImageID].imagepath}</td>
        {%if $smarty.section.ImageID.rownum is div by 2%}
        </tr>
        <tr>
        {%/if%}
    <%/section%>
    </tr>
    但还是不对,name=ImageID 是什么意思, {if $smarty.section.ImageID.rownum is div by 2}是什么意思
    我运行的结果是:
    {%if $smarty.section.ImageID.rownum is div by 2%}  
    {%/if%}  {$ImageList[ImageID].imagepath} {%if $smarty.section.ImageID.rownum is div by 2%}  
    {%/if%}  {$ImageList[ImageID].imagepath} {%if $smarty.section.ImageID.rownum is div by 2%}  
    {%/if%}  {$ImageList[ImageID].imagepath} {%if $smarty.section.ImageID.rownum is div by 2%}  
    {%/if%}  {$ImageList[ImageID].imagepath} {%if $smarty.section.ImageID.rownum is div by 2%}  
    {%/if%}  {$ImageList[ImageID].imagepath} {%if $smarty.section.ImageID.rownum is div by 2%}  
    {%/if%}  {$ImageList[ImageID].imagepath} {%if $smarty.section.ImageID.rownum is div by 2%}  
    {%/if%}  {$ImageList[ImageID].imagepath} {%if $smarty.section.ImageID.rownum is div by 2%}  
    {%/if%}  {$ImageList[ImageID].imagepath} 没有报错,直接输出上面的信息了
    望帮忙.
      

  4.   

    1)你的边界符是定义为<% %>了?我是用默认的{}你要使用我这段的程序,应该把我程序中的"{"替换成"<%",把"}"替换成"%>",这样才能执行。否则smarty根本认不出{}。2)name=ImageID,name是section的一个属性,指section所控制循环数组在tpl中的下标变量,使用的时候ImageID从0开始,到你所循环的层数结束。具体可以参考smarty手册。3) {if $smarty.section.ImageID.rownum is div by 2}这句是指如果本次循环的次数能够被2整除,那么执行if中间的语句。在这个程序中,就是起到换一个<tr>的作用。smarty手册上也有详细地说明。
      

  5.   

    smarty 如果
    <tr> 
    <section name=ImageID loop=$ImageList>
        <td width="100">{$ImageList[ImageID].ImageName}</td>
        {if $smarty.section.ImageID.rownum is div by 2}
        </tr>
        <tr>
        {/if}
    </section>
    </tr>
    这样用.那么有什么意义呢。让美工学会一门页面语言吗。而且看上去那么难看!! DW打开就是错!! 跟本没有办法看到效果!! 得,基本上也等于把DW废除了!! 锻炼页面的抽象思维能力啊!!摸板的目的就是程序与页面分离,说白了,就是逻辑与页面分离.
    把页面的逻辑关系做到最少,那就是成功了!!我最近写个东西。在程序中我抛出了所有前台可能用到的变量.比如产品的循环,最多前台显示多少 ?? 一般20个够了吗.那我就在程序中都抛出来. 那么好了,页面你随便想去把.你想把前边爱怎么摆怎么摆.爱怎么放怎么放!! 当然对那些小活没有必要了。可是我写的这个就是为了给需要多摸版的程序用的.程序开发起来比较耗时间,但是后期你就爽了 !!!东西我已经写完了。 最后我整理了一个CHM手册,告诉美工,你调用这个程序 例如: <{ include_php file="Top.php"}> 那么去查我给你的手册吧. 这个里边有那些变量你可以随意调用,然后好了。你去设计吧.我想摸版对于WEB开发。应该是这样的一个作用!!