不求最好,但求最复杂[来自QQ群]
2008-05-08 14:15
197 查看
1.从PHP分配的变量
调用从PHP分配的变量需在前加"$"符号.(译注:同php一样)
调用模板内的assign函数分配的变量也是这样.(译注:也是用$加变量名来调用)
Eg:
$smarty->assign('lastLoginDate', 'January11th, 2001');
$smarty->display('index.tpl');
index.tpl:
Hello {$firstname}, glad to see you couldmake it.
<p>
Your last login was on {$lastLoginDate}.
OUTPUT:
Hello Doug, glad to see you could make it.
<p>
Your last login was on January 11th, 2001.
2.从配置文件读取的变量
配置文件中的变量需要通过用两个"#"或者是smarty的保留变量 $smarty.config.来调用(下节将讲到)
第二种语法在变量作为属性值并被引号括住的时候非常有用.
(译注:举个例子 {include file="#includefile#"} 这样#includefile#将被当作字符处理,而不表示配置文件变量,但可以这样表示{include file="`$smarty.config.includefile`"}不要忘了加``)
Eg:
配置文件的变量只有在它们被加载以后才能使用.
调用从PHP分配的变量需在前加"$"符号.(译注:同php一样)
调用模板内的assign函数分配的变量也是这样.(译注:也是用$加变量名来调用)
Eg:
index.php: $smarty = new Smarty; $smarty->assign('firstname', 'Doug');
$smarty->assign('lastLoginDate', 'January11th, 2001');
$smarty->display('index.tpl');
index.tpl:
Hello {$firstname}, glad to see you couldmake it.
<p>
Your last login was on {$lastLoginDate}.
OUTPUT:
Hello Doug, glad to see you could make it.
<p>
Your last login was on January 11th, 2001.
2.从配置文件读取的变量
配置文件中的变量需要通过用两个"#"或者是smarty的保留变量 $smarty.config.来调用(下节将讲到)
第二种语法在变量作为属性值并被引号括住的时候非常有用.
(译注:举个例子 {include file="#includefile#"} 这样#includefile#将被当作字符处理,而不表示配置文件变量,但可以这样表示{include file="`$smarty.config.includefile`"}不要忘了加``)
Eg:
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 bgcolor="{#bodyBgColor#}">
<table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}">
<tr bgcolor="{#rowBgColor#}">
<td>First</td>
<td>Last</td>
<td>Address</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.tableBorderSize}"bgcolor="{$smarty.config.tableBgColor}">
<tr bgcolor="{$smarty.config.rowBgColor}">
<td>First</td>
<td>Last</td>
<td>Address</td>
</tr>
</table>
</body>
</html>
OUTPUT:
<html>
<title>This is mine</title>
<body bgcolor="#eeeeee">
<table border="3" bgcolor="#bbbbbb">
<tr bgcolor="#cccccc">
<td>First</td>
<td>Last</td>
<td>Address</td>
</tr>
</table>
</body>
</html>
配置文件的变量只有在它们被加载以后才能使用.
相关文章推荐
- 临终须知1--来自qq群
- bash技巧[来自QQ群交流]
- 关于初级磁盘管理(gpt UEFI...)最好的一篇文章(来自gentoo linux)
- 七个最好的职业建议(来自阮一峰的博客)
- 史上最好用侧滑布局来自代码家大神的SwipeLayout(基于ViewDragHelper)
- java解析String类型t复杂xml,多级节点,最好的例子
- 地震后遗症 [ 来自 QQ群]
- 来自于世界上最好博客的47个博客技巧 中文版
- 开源中最好的Web开发的资源 ——来自CoolShell.cn
- 开源中最好的Web开发的资源 ——来自CoolShell.cn
- ACM算法-时间复杂度分析(2.最坏,平均,最好时间复杂度分析)
- 【转】我读过最好的epoll讲解(来自知乎)
- 厕所对联[来自QQ群]
- gentoo启动脚本 mdev Activating [来自QQ群]
- 不求最好,但求最2
- [LeetCode] string整体做hash key,窗口思想复杂度O(n)。附来自LeetCode的4例题(标题有字数限制,写不下所有例题题目 T.T)
- 网络运维,不求最贵,但求最好
- 来自于世界上最好博客的47个博客技巧
- 有一亿个int整数---找到前top10 最大的数 ---最好考虑时间复杂度
- Db2 v8最好的上手试验教程-来自IBM官方