Smarty变量用法详解_.docx

上传人:啊飒飒 文档编号:11651335 上传时间:2021-08-28 格式:DOCX 页数:5 大小:12.32KB
返回 下载 相关 举报
Smarty变量用法详解_.docx_第1页
第1页 / 共5页
Smarty变量用法详解_.docx_第2页
第2页 / 共5页
Smarty变量用法详解_.docx_第3页
第3页 / 共5页
Smarty变量用法详解_.docx_第4页
第4页 / 共5页
Smarty变量用法详解_.docx_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《Smarty变量用法详解_.docx》由会员分享,可在线阅读,更多相关《Smarty变量用法详解_.docx(5页珍藏版)》请在三一文库上搜索。

1、Smarty变量用法详解_ 本文实例讲解并描述了Smarty变量用法。分享给大家供大家参考,具体如下: 1. 从PHP安排的变量 调用从PHP安排的变量需在前加$符号.(译注:同php一样) 调用模板内的assign函数安排的变量也是这样.(译注:也是用$加变量名来调用) 示例: index.php: $smarty = new Smarty; $smarty-assign(firstname, Doug); $smarty-assign(lastLoginDate, January11th, 2021); $smarty-display(index.tpl); index.tpl: Hell

2、o $firstname, glad to see you couldmake it. p Your last login was on $lastLoginDate. 输出: Hello Doug, glad to see you could make it. p Your last login was on January 11th, 2021. 2. 从配置文件读取的变量 配置文件中的变量需要通过用两个#或者是smarty的保留变量 $smarty.config.来调用(后面会讲到) 其次种语法在变量作为属性值并被引号括住的时候特别有用. (译注:举个例子 include file=#i

3、ncludefile# 这样#includefile#将被当作字符处理,而不表示配置文件变量,但可以这样表示include file=$smarty.config.includefile不要忘了加) 示例: foo.conf: pageTitle = This is mine bodyBgColor = #eeeeee tableBorderSize = 3 tableBgColor = #bbbbbb rowBgColor = #cccccc index.tpl: config_load file=foo.conf html title#pageTitle#/title body bgcol

4、or=#bodyBgColor# table border=#tableBorderSize# bgcolor=#tableBgColor# tr bgcolor=#rowBgColor# tdFirst/td tdLast/td tdAddress/td /tr /table /body /html index.tpl: config_load file=foo.conf html title$smarty.config.pageTitle/title body bgcolor=$smarty.config.bodyBgColor table border=$smarty.config.ta

5、bleBorderSizebgcolor=$smarty.config.tableBgColor tr bgcolor=$smarty.config.rowBgColor tdFirst/td tdLast/td tdAddress/td /tr /table /body /html 上述两种模板写法都输出: html titleThis is mine/title body bgcolor=#eeeeee table border=3 bgcolor=#bbbbbb tr bgcolor=#cccccc tdFirst/td tdLast/td tdAddress/td /tr /table /body /html 配置文件的变量只有在它们被加载以后才能用法. 盼望本文所述对大家基于smarty模板的PHP程序设计有所关心。 .

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1