Smarty

来源:互联网 发布:刘轩豪网络 诈骗 编辑:程序博客网 时间:2024/05/16 11:38

Smarty的安装

安装类似于ecshop。

只需要将libs文件夹拷贝到服务器目录下即可。

templates:存放页面模板,路径任意。

templates_c:存放编译之后的页面模板。(在后台数据部发生变化时,打开网站调用的是编译之后的模板。里面的文件系统自动生成)

configs:模板所需要的特殊的配置文件

cache:存放Smarty缓存内的模板(临时)

应用Smarty

1.引入Smarty.class.php的文件

2.创建Smarty对象

3.更改模板存放路径及编译路径(templates_dir  compile_dir)

4.修改界定符(left_delimiter  right_delimiter)

5.编写模板(*.tpl(就是html))里面的数据部分用Smarty变量表示

6.在php文件中用assign方法给模板中的变量赋值

7.在php文件中用display方法将模板及数据显示。

模板注释被*号包围,例如 {* this is a comment *}

配置文件中的变量需要通过用两个"#"或者是smarty的保留变量$smarty.config.来调用

配置文件的变量只有在它们被加载以后才能使用.{config_load file=”配置文件名” section = “局部变量”}

{$smarty}保留变量

页面请求变量](就是get,post,server,session等变量)

<{$smarty.cookies.name}>

<{$smarty.session.name}>

<{$smarty.get.id}>

<{$smarty.post.name}>

{$smarty.now}

<{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}>

<{$smarty.config.edit}>

<{$smarty.foreach.a1.total}>

<{$smarty.section.a1.index}>
原创粉丝点击