160726 smarty 笔记(1)
模板里面显示变量:
1.变量要写在Smarty标记之间,变量名以$开头
<{$test}>
2.支持所有类的数据,包括数组(关联数组),对象
关联数组在模板显示的时候,除了可以使用php语法之外,还支持点语法 <{$attr.name}>
小知识点:
<{*模板内容注释*}>
<{literal}>
<{忽略smarty,内容原样输出,不参与解析}>
<{/literal}>
针对索引数组
<{$shuzu["one"]}>
<{$shuzu.one}>
调用封装类里面的元素
![](https://images2015.cnblogs.com/blog/932676/201607/932676-20160729122111466-1598735605.png)
<{$duixiang->uid}>
模板里面读取配置文件
1.将配置文件加载到当前页面
<{config_load file='test.conf'}>
2.读取配置中的内容
<{#color#}>
3.如果配置文件中分了块,怎么读某一块的配置
<{config_load file='test.conf' section='块名'}>
<{config_load file='test.conf' section="one"}>
<div style="width: 200px;height: 80px;font-size: 20px;
font-weight: bold;background-color: <{#bgcolor#}> ;color: <{#color#}>;">
第一个DIV她又瞧了瞧自己的活
</div>
<{config_load file='test.conf' section="two"}>
<div style="width: 200px;height: 80px;font-size: 20px;
font-weight: bold;background-color:<{#bgcolor#}>;color:<{#color#}> ;">
第二个DIV珊莎正一边巧手缝纫
</div>
![](https://images2015.cnblogs.com/blog/932676/201607/932676-20160729122227794-369156230.png)
![](https://images2015.cnblogs.com/blog/932676/201607/932676-20160729122313309-1277252235.png)
![](https://images2015.cnblogs.com/blog/932676/201607/932676-20160729122336856-871002544.png)
Smarty保留变量
$smarty.const 读取常量 例如:CSS,JS,图片的存放路口
变量调节器:
关键字:modifier
1.系统自带的变量调节器:转大写 转小写 首字母大写 截取字符串 拼接字符串
2.自定义变量调节器:
变量调节器存放目录下新建文件:modifier.调节器名称.php
在该文件里面新建一个方法:function smarty_modifier_调节器名($str){}
$str参数代表调用该调节器的变量
最后该方法要有一个返回值
![](https://images2015.cnblogs.com/blog/932676/201607/932676-20160729122507450-1682396759.png)
![](https://images2015.cnblogs.com/blog/932676/201607/932676-20160729122532716-1322200042.png)
![](https://images2015.cnblogs.com/blog/932676/201607/932676-20160729122844638-1677695532.png)
![](https://images2015.cnblogs.com/blog/932676/201607/932676-20160729122909872-228234437.png)
![](https://images2015.cnblogs.com/blog/932676/201607/932676-20160729122940059-2064309059.png)
![](https://images2015.cnblogs.com/blog/932676/201607/932676-20160729123209372-1474685384.png)
![](https://images2015.cnblogs.com/blog/932676/201607/932676-20160729123222434-1243684500.png)
![](https://images2015.cnblogs.com/blog/932676/201607/932676-20160729123232622-1456374779.png)
![](https://images2015.cnblogs.com/blog/932676/201607/932676-20160729123240653-337482652.png)
![](https://images2015.cnblogs.com/blog/932676/201607/932676-20160729123248169-164830546.png)
![](https://images2015.cnblogs.com/blog/932676/201607/932676-20160729123259184-1601245973.png)
![](https://images2015.cnblogs.com/blog/932676/201607/932676-20160729123308106-1240150865.png)
![](https://images2015.cnblogs.com/blog/932676/201607/932676-20160729123319934-1645544015.png)