smarty模板section,foreach循环用法
2016-05-04 00:41
351 查看
{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
}
{/section}
结果则是:
section循环
元素:
元素:
元素:
元素:无内容
如果把数组arr的元素换成‘two’=>array()等,循环到元素two时同样无法得到结果。
$arr=array('object'=>'book','type'=>'computer');
smarty模板文件中对数组的读取:1.通过索引$arr[0];2.通过键值,$arr.type
{$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
}
{/section}
结果则是:
section循环
元素:
元素:
元素:
元素:无内容
如果把数组arr的元素换成‘two’=>array()等,循环到元素two时同样无法得到结果。
$arr=array('object'=>'book','type'=>'computer');
smarty模板文件中对数组的读取:1.通过索引$arr[0];2.通过键值,$arr.type
相关文章推荐
- POJ 1064 Cable master (二分)
- POJ 2431 Expedition(优先队列、贪心)
- R语言手动计算主成分分析(PCA)及其在R函数的实现
- day4.09总结_Menu 菜单
- PHP之验证码的实现
- day4.08总结_UI控件
- immutableJS一些API
- 让IIS支持无后缀名访问
- web前端开发初学者十问集锦(1)
- Java动态代理的异常处理问题
- web前端开发初学者十问集锦(1)
- php实习的tips(常用的head头)
- php的tips(生成随机函数rand与srand)
- day4.06总结_Adapter自定义和优化和ListView
- Android中资源文件的使用
- 20160504收获
- 仿带噪点和横线的验证码自定义View
- day4.05总结_Adapter和Listview的优化
- windows下利用ffmpeg进行视频格式转换
- cocos2d-x-3.x snapshot