|
用几个小时把SMARTY类的电子书大致翻了下
摘录了SMARTY的若干特性
做个笔记:
1,安装:
所谓“安装”,就是让PHP能够找到Smarty.class.php文件
最简单的办法是把下载的SMARTY解压到你的项目上
稍复杂的办法是改php.ini 的include_path目录
2,从配置文件引用变量
x.tpl
{config_load file="sample.conf"}
<html><head>
<title>{#title#}</title>
</head>
<body>
另一种表达法:<a href="" title="{$smarty.config.title}">HEllo</a>
注意:是smarty.config而非实例化后的smarty对象
</body>
</html>
sample.conf
title="Hello config_file"
3,{$smarty}保留变量
3.1 Request Variables (get post server session四个)
3.2 now const capture config section foreach template
用法:
{$smarty.get.page}
capture:
{capture name="button"}
<input type="button" value="Capture" />
{/capture}
{if $smarty.capture.button ne ""}
{$smarty.capture.button}
{/if}
4格式符:
{$var|format:"format string"}
例:{$title|default:"no title"}
{$redirectUrl|escape:"url"}
{$articleTitle|nl2br} newline(即\n) to <br />
{$articleTitle|regex_replace:"/查找表达式/":"替换表达式"}
{$test|replace:"要替换的内容":"替换成的内容"}
5 怎么输出{}??
{ldelim}{rdelim}
6 类似于 echo <<< _html;
<a href="" >adfs</a>
-html;
的功能:{literal} {/literal} (smarty内部是否就是这样实现?)
7{php}{/php}
8 简写的DataGrid颜色分层
{section name=rows loop=$data}
<tr bgcolor="{cycle values="#eeeeee,#d0d0d0"}">
<td>{data[rows]}</td>
</tr>
{/section}
9{fetch file="/export/httpd/www.domain.com/docs/navbar.js"}
10 灵活地设置cache可以加速,设置config可以轻松定义不同界面风格
到此为止,只欠一次全面查阅了!
[ 本帖最后由 iptton 于 2007-1-13 00:51 编辑 ] |
|