JAVA、PHP、前端、APP、网站开发 - 开发技术学习

开发技术学习 » 编程开发 » Thinkphp中使用smarty模板引擎的一些知识收集

Thinkphp中使用smarty模板引擎的一些知识收集

此文被围观3298 日期: 2012-09-05 分类 : 编程开发  标签:  ·······
客户要求要用smarty模板引擎来做,本来我们电子商务组这边一直都是使用的thinkphp的模板引擎,而且大家结这块都很了解了。 却不曾想到客户有这种要求,于是乎大家开始在thinkphp上引用smarty,但是过程确实复杂啊! 走了不少弯路。 分隔不需要编译的代码{literal}{/literal} {:U("")} 不能用,要用{U("")} <include file="" />不能用,要改成{include file=""}. thinkphp框架自带的模板跟smarty模板很像,但是也有很多差别。 说说他们的对应关系: 1、 <present name="nodeName">[{$nodeName}] </present> smarty模板为: {if !empty($nodeName)}[{$nodeName}]{/if} 2、 <eq name="level" value="1">应用</eq> smarty模板为: {if $level == '1'}应用 3、 <volist name="groupList" id="tag"><a href="/index.php/Article/index/group_id/{$key}">{$tag}</a> </volist> smarty模板为: {foreach from=$groupList item=tag key=key} <a href="/index.php/Article/index/group_id/{$key}">{$tag}</a> {/foreach} 4、 {$Think.session.loginUserName} smarty模板为: {$smarty.session.loginUserName} 5、 <html:imageBtn name="add" value="新增" click="add()" style="impBtn hMargin fLeft shadow" /> smarty模板为: <div class="impBtn hMargin fLeft shadow" > <input type="button" id="add" name="add" value="新增" class="add imgButton"> </div> 6、来一个比较复杂的 <html:list id="checkList" name="node" style="list" checkbox="true" action="true" datasource="list" show="id:编号|10%,name:名称:child,title:显示名:edit,group_id|getNodeGroupName:分组,sort:序号,status|getStatus:状态" actionlist="status|showStatus=$node['id'],edit:编辑:id" /> smarty模板为: <!-- Think 系统列表组件开始 --> <table id="checkList" class="list" cellpadding=0 cellspacing=0 > <tr><td height="5" colspan="8" class="topTd" ></td></tr> <tr class="row" > <th width="8"><input type="checkbox" id="check"></th> <th width="10%"><a href="javascript:sortBy('id','1','index')" title="按照编号升序排列 ">编号<img src="/thinkphp/xww/Rbac/Tpl/default/Public/images/desc.gif" width="12" height="17" border="0" align="absmiddle"></a></th> <th><a href="javascript:sortBy('name','1','index')" title="按照名称升序排列 ">名称</a></th><th><a href="javascript:sortBy('title','1','index')" title="按照显示名升序排列 ">显示名</a></th><th><a href="javascript:sortBy('group_id','1','index')" title="按照分组升序排列 ">分组</a></th> <th><a href="javascript:sortBy('sort','1','index')" title="按照序号升序排列 ">序号</a></th><th><a href="javascript:sortBy('status','1','index')" title="按照状态升序排列 ">状态</a></th> <th >操作</th> </tr> {foreach item=item from=$list} <tr class="row" > <td><input type="checkbox" name="key" value="{$item.id}"></td> <td>1</td> <td><a href="javascript:child({$item.id})">{$item.name}</a></td> <td><a href="javascript:edit({$item.id})">{$item.title}</a></td> <td> {if $item.group_id eq 0} 未分组 {else} 已分组 {/if} </td> <td></td> {if $item.status eq 1} <td><IMG SRC="/thinkphp/xww/Public/Images/ok.gif" WIDTH="20" HEIGHT="20" BORDER="0" ALT="正常"></td> {else} <td><IMG SRC="/thinkphp/xww/Public/Images/locked.gif" WIDTH="20" HEIGHT="20" BORDER="0" ALT="禁用"></td> {/if} <td> {if $item.status eq 1} <a href="javascript:forbid({$item.id})">禁用</a> {else} <a href="javascript:resume({$item.id})">恢复</a> {/if} <a href="javascript:edit({$item.id})">编辑</a> </td> </tr> <tr><td height="5" colspan="8" class="bottomTd"></td> </tr> {/foreach} </table> <!-- Think 系统列表组件结束 -->   在这里另附smarty在线中英文对照手册:http://www.php100.com/manual/smarty/index.html

站点声明:部分内容源自互联网,为传播信息之用,如有侵权,请联系我们删除。

© Copyright 2011-2024 www.kfju.com. All Rights Reserved.
超级字帖 版权所有。 蜀ICP备12031064号      川公网安备51162302000234