zoukankan      html  css  js  c++  java
  • smarty模板section,foreach循环用法

    {foreach name=foreach_name key=k item=v from=$arr}

    {$k}=>{$v}<br/>

    {/foreach} 


    {section name=sec_name loop=$arr start=0 step=n max= m show=true/false }

    {if is_array($arr[sec_name])}

     {section name=sec2 loop=$arr[sec_name]}

    {$arr[sec_name][sec2]}<br/> 

    {/section}

    {esle}

     {$arr[sec_name]}<br/>

    {/if} 

    {$smarty.section.sec_name.index}{*当前循环下标,默认为0,例如0,1,2,3...*} 

    {$smarty.section.sec_name.index_prev}{*当前循环下标的前一个值,index为0时,index_prev为-1*}

    {$smarty.section.sec_name.index_next}{*后一个值,默认为1*}

    {$smarty.section.sec_name.first}{*是否为第一个循环,是为true*}

    {$smarty.section.sec_name.last}{*是否为最后一个循环*}

    {$smarty.section.sec_name.iteration}{*当前行号,如1,2,3,4...*}rownum是iteration的别名

    {$smarty.section.sec_name.loop}{*最后一个循环号,数组元素为7个,实际循环4次(例:max=4),loop仍然显示为7*} 

    {$smarty.section.sec_name.total}{*实际循环次数*} 

    max规定最大循环次数;

    show是否显示这部分内容;决定是否对这块进行显示 

    {/section}

    section在 循环一维带键值的数组时,无法显示数组内容:

    例如:$arr=array('one'=>'bo','two'=>"yuan",'three'=>'mm','four'=>'bb'); 

    {section name=n loop=$arr}

    元素:{$arr[n]} 

    {/section} 

     结果则是:

    section循环

    元素:
    元素:
    元素:
    元素:

    无内容

    如果把数组arr的元素换成‘two’=>array()等,循环到元素two时同样无法得到结果。

    $arr=array('object'=>'book','type'=>'computer'); 

    smarty模板文件中对数组的读取:1.通过索引$arr[0];2.通过键值,$arr.type

  • 相关阅读:
    POJ
    HDU
    Python之列表
    列表、元组、字典总结
    Python之列表、原组、字典总结
    [P1082][NOIP2012] 同余方程 (扩展欧几里得/乘法逆元)
    [P3957][NOIP2017]跳房子 (DP+二分/队列?)
    [Codeforces896C] Willem, Chtholly and Seniorious (ODT-珂朵莉树)
    [P1005][NOIP2007] 矩阵取数游戏 (DP+高精)
    [POJ1006]生理周期 (中国剩余定理)
  • 原文地址:https://www.cnblogs.com/feng12345/p/5457039.html
Copyright © 2011-2022 走看看