Chinaunix首页 | 论坛 | 博客
  • 博客访问: 26311728
  • 博文数量: 2065
  • 博客积分: 10377
  • 博客等级: 上将
  • 技术积分: 21525
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-04 17:50
文章分类

全部博文(2065)

文章存档

2012年(2)

2011年(19)

2010年(1160)

2009年(969)

2008年(153)

分类:

2009-07-02 19:26:08

1.此模板语言从配置文件中读取我们所想要的变量数据出来!
假如配置文件是:
foo.conf: pageTitle = "This is mine" bodyBgColor = "#eeeeee" tableBorderSize = "3" tableBgColor = "#bbbbbb" rowBgColor = "#cccccc"
我们的数据格式是这样的:
{config_load file="foo.conf"} {#pageTitle#}
First Last Address

现在将这里面的数据由标签动态提取出来
{config_load file="foo.conf"} {$smarty.config.pageTitle}
First Last Address

通过标签的语法:$smarty.config.pageTitle  通过confie变量进行提取出来相关变量!
其输出的格式如下:
OUTPUT: (same for both examples) This is mine
First Last Address

2.页面请求变量
相当于我们的PHP中取GET POST数据的操作!
以下是访问页面请求变量诸如get,post,cookies,server,enviroment和session变量的例子.
{* display value of page from URL (GET)  *}
{$smarty.get.page}

{* display the variable "page" from a form a form (POST) *}
{$smarty.post.page}

{* display the value of the cookie "username" *}
{$smarty.cookies.username}

{* display the server variable "SERVER_NAME" *}
{$smarty.server.SERVER_NAME}

{* display the system environment variable "PATH" *}
{$smarty.env.PATH}

{* display the php session variable "id" *}
{$smarty.session.id}

{* display the variable "username" from merged get/post/cookies/server/env *}
{$smarty.request.username}
3. 来看看这个模板语言中的常用的变量的含义吧!就相当于已定义好的变量我们可以直接拿过来用的!
{$smarty.now}变量用于访问 当前时间戳.可以用 date_format调节器格式化输出.
变量:$smarty.now表示我们的smarty中的一个变量!
例示:
{* use the date_format modifier to show current date and time *}
{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"} 此模板语言也有自带的函数哦!不过这个函数写法跟我们的PHP
的还不一样的哦!

4.{$smarty.const._MY_CONST_VAL} 你可以直接访问PHP常量.
通过$smarty.const的方式进行就可以直接访问我们的PHP常量了!


{$smarty}变量 可以访问已经加载的config变量.
例如 {$smarty.config.foo}就可以表示 {#foo#}.可以查看 部分的例子.

此Smarty变量是用来读取配置文件中的变量信息出来的!

5.

阅读(956) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

hkebao2009-07-03 09:22:26

http://hi.baidu.com/persimmom1/blog/item/ea7dad1bcdf35e1c8718bf7c.html 看一下Smarty方面的示例就能明白了