smarty的保留变量:
保留变量可以被用于访问一些特殊的模板变量.
smarty打印保留变量:
在模板中如果要将smarty的一些保留字作为语言的内容显示出来,如显示分隔符,(默认为{})可用以下几种方法:
方法一:{ldelim},{rdelim}
方法二:{$smarty.ldelim},{$smarty.rdelim}
方法三:把{}放在{literal} .. {/literal} 中间输出。
保留变量例表:
页面请求变量: get,post,cookies,server,enviroment和session
例:
{$smarty.server.SERVER_NAME}取得服务器变量,
{$smarty.env.PATH}取得系统环境变量path,
{$smarty.request.username}取得get/post/cookies/server/env的复合变量。
时间变量:
{$smarty.now}变量用于访问当前时间戳.
date_format调节器格式化输出. 例如{$smarty.now|date_format:"%Y-%m-%d
%H:%M:%S"}
常量:
{$smarty.const}
你可以直接访问PHP常量. 例如{$smarty.const._MY_CONST_VAL}
截取输出:
{$smarty.capture}
可以通过 {capture}..{/capture}结构 截取的输出,可以使用{$smarty} 变量访问.
配置访问:
{$smarty.config}
{$smarty}变量 可以访问已经加载的config变量.
例如 {$smarty.config.foo}就可以表示
{#foo#}.
循环:
{$smarty.section}, {$smarty.foreach}
{$smarty} 变量可以访问'section'和'foreach'循环的属性.
模版处理:
{$smarty.template}
显示当前被处理的模板的名字.
版本查看:
{$smarty.version}
显示smarty模板的版本
分隔符:
{$smarty.ldelim}
{$smarty.rdelim}
显示左右分隔符
保留变量循环应用举例:
$smarty.section.loop(这里写的是你section设的name).index
index是从0开始
$smarty.section.loop(这里写的是你section设的name).iteration
iteration是从1开始
$smarty.section.loop(这里写的是你section设的name).rownum
rownum是iteration的别名
附一个例子;
{section name=customer loop=$custid}
{$smarty.section.customer.index} id:
{$custid[customer]}<br/>
{/section}
或者
<{foreach name= customer item=i key=k from=$custid }>
<{$smarty.foreach.customer.iteration}>…
<{/foreach}>OUTPUT:
0 id: 1000<br>
1 id: 1001<br>
2 id: 1002<br>