smarty section循环
2016-03-21 10:42
225 查看
{section name = name loop = $varName[, start = $start, step = $step, max = $max, show = true]} |
name: section的名称,不用加$ $loop: 要循环的变量,在程序中要使用assign对这个变量进行操作。 $start: 开始循环的下标,循环下标默认由0开始 $step: 每次循环时下标的增数 $max: 最大循环下标 $show: boolean类型,决定是否对这个块进行显示,默认为true |
{section name=loop loop=$News} 新闻编号:{$News[loop].newsID} 新闻标题:{$News[loop].newsTitle} {sectionelse} 对不起,没有任何新闻输入! {/section} |
<? /********************************************* * * 文件名: example7.php * 作 用: 显示实例程序2 *********************************************/ include_once("./comm/Smarty.class.php"); $smarty = new Smarty(); $smarty->templates("./templates"); $smarty->templates_c("./templates_c"); $smarty->cache("./cache"); $smarty->cache_lifetime = 0; $smarty->caching = true; $smarty->left_delimiter = "{"; $smarty->right_delimiter = "}"; $array[] = array("newsID"=>1, "newsTitle"=>"第1条新闻"); $array[] = array("newsID"=>2, "newsTitle"=>"第2条新闻"); $array[] = array("newsID"=>3, "newsTitle"=>"第3条新闻"); $array[] = array("newsID"=>4, "newsTitle"=>"第4条新闻"); $array[] = array("newsID"=>5, "newsTitle"=>"第5条新闻"); $array[] = array("newsID"=>6, "newsTitle"=>"第6条新闻"); $smarty->assign("newsArray", $array); //编译并显示位于./templates下的index.tpl模板 $smarty->display("example.tpl"); ?> |
这里将输出一个数组: 新闻编号:1 新闻内容:第1条新闻 新闻编号:2 新闻内容:第2条新闻 新闻编号:3 新闻内容:第3条新闻 新闻编号:4 新闻内容:第4条新闻 新闻编号:5 新闻内容:第5条新闻 新闻编号:6 新闻内容:第6条新闻 |
相关文章推荐
- smarty 入门
- absolute与relative怎么区分,
- Warning: Cannot modify header information - headers already sent by....
- 2013年03月21日
- stdClass是PHP的一个基类
- PHP正则表达式 /i, /is, /s, /isU等
- 关于PHP5 Session生命周期介绍
- MySql查询结果按照指定顺序排序
- <meta http-equiv=...> 的功能
- Smarty模板中变量修饰格式: {$var|方法1:参数1:参数2…|方法2…}
- php curl_init函数用法
- background-position属性
- 2013年04月03日
- 2013年04月03日
- crontab命令的功能是在一定的时间间隔调度一些命令的执行
- 关于千千静听在win7系统下无法打开网络媒体
- 两个卖家之间互相买东西,算不算违规
- PHP文件上传至另一台服务器
- windows提示电脑已经关机了但主机还在运行
- iframe去掉滚动条