001 - smarty 模板嵌套
来源:互联网 发布:蓝光软件 编辑:程序博客网 时间:2024/05/18 03:28
smarty 模板数据镶嵌1、直接套入$data. ----> 为最外层的Attr (无需循环,直接点上既可以) 2、循环列表1、foreach 循环 {{foreach item=item form=$data.banner key=k name=name}} <li> {{$item.links}} </li> -----> 用item. 上下面的子元素 {{if $k==0}} k=0 {{/if}} -----> k 拿到的是索引值 以此来做判断 {{/foreach}} 如果想在其他地方拿到 name为name循环中的数据 //判断 {{$smarty.foreach.name.first}} ---> 循环里面的第一个 {{$smarty.foreach.name.last}} ---> 循环里面的最后一个 {{$smarty.foreach.name.index < 5}} ---> 循环中的索引值 | 2、section 循环| {{section name=name loop=$data.product}}| //判断| {{$smarty.section .name.last}} -----> name为name的循环中 最后一个数组有效的话.... //嵌套数据 {{$data.product[name]. xxxx ?}} loop[name]. xxxx ? {{/section}} 3、条件判断 基本结构: {{if $data.xxx}} abc {{else}} 123 {{/if}} 判断一个数组的长度: {{if $data.attr|count > 3}} {{if $data.range_tags|@count > 1}}
4、引入其他文件{{include file="boxs/ad.html"}} 5、返回上一级按钮 {{if $data.back}} <a id="back" href="javascript:history.go(-1)" class="ico2 f_l"></a> {{else}} <a id="back" back="true" class="ico2 f_l"></a> {{/if}}6、关于.html页面的JS使用 smarty问题<script type="text/javascript">注意:smarty 不可用在.JS文件中var JS_productInfoUrl = "{{$data.JS_productInfoUrl}}"; //然后即可操作此变量 </script>
1 0