内建函数解析
2011-11-17 18:52
141 查看
今天主要讲解的是smarty的内建函数,涉及到的内建函数包括:
1、 config_load:加载配置文件
语法:<{config_load file=”配置文件名称” section=“区域名称” }>
2、Include:标签用于在当前模板中包含其它子模板.
当前模板中的变量在被包含的子模板中可用
语法:<{include file="加载文件名称"}>
3、 capture:捕获模板输出的数据并将其存储到一个变量里,而不是把它们输出到页面.
演示:<{capture name="one"}>
aaaaaaaaa<br>
<{/capture}>
使用smarty保留变量显示该区域内容<br>
<{$smarty.capture.one}><br>
结果:aaaaaaaaa
4、foreach,foreachelse:功能和语法与php当中类似,====foreach
5、Interation:用于显示当前循环的执行次数,从1开始,每执行一次增加 1
6、section,sectionelse:功能和效率要比foreach好
7、if,elseif,else
由于后边几个内置函数实现过程繁琐,下面通过演示一个section循环来给大家演示一下:(注:以下代码只是文件的一部分)
a.html
演示session循环的使用<br>
二维数组的显示<br>
<table border="1">
<{section loop=$data name=out}>
<tr>
<td><{$data[out].productID}></td>
<td><{$data[out].name}></td>
<td><{$data[out].price}></td>
<td><{$data[out].description}></td>
<td><{section loop=$data[out].a name=in}>
<{$data[out].a[in].one}>
<{/section}></td>
</tr>
<{sectionelse}>
数组有问题
<{/section}>
b.php
<?php
include("./init.inc.php");
$tpl->assign("name","abc");
//连接数库据,产生连接对象$mysqli
$mysqli = new mysqli("localhost","root","","product");
//执行sql语句,返回结果及对象$result
$result = $mysqli->query("select * from product");
//针对二维数组
$data=array();
while($row = $result->fetch_assoc()){
$row["a"]=array(array("one"=>"aaaaaaa"),array("two"=>"bbb"));
$data[]=$row;
}
//将$row分配到模版变量里
$tpl->assign("data",$data);
//测试if条件、分配变量
$tpl->assign("val",2);
$tpl->display("a.html");
?>
演示结果:
二维数组的显示
由于上述代码只是一些文件的一部分,若实现功能不完全,请多指点。
1、 config_load:加载配置文件
语法:<{config_load file=”配置文件名称” section=“区域名称” }>
2、Include:标签用于在当前模板中包含其它子模板.
当前模板中的变量在被包含的子模板中可用
语法:<{include file="加载文件名称"}>
3、 capture:捕获模板输出的数据并将其存储到一个变量里,而不是把它们输出到页面.
演示:<{capture name="one"}>
aaaaaaaaa<br>
<{/capture}>
使用smarty保留变量显示该区域内容<br>
<{$smarty.capture.one}><br>
结果:aaaaaaaaa
4、foreach,foreachelse:功能和语法与php当中类似,====foreach
5、Interation:用于显示当前循环的执行次数,从1开始,每执行一次增加 1
6、section,sectionelse:功能和效率要比foreach好
7、if,elseif,else
由于后边几个内置函数实现过程繁琐,下面通过演示一个section循环来给大家演示一下:(注:以下代码只是文件的一部分)
a.html
演示session循环的使用<br>
二维数组的显示<br>
<table border="1">
<{section loop=$data name=out}>
<tr>
<td><{$data[out].productID}></td>
<td><{$data[out].name}></td>
<td><{$data[out].price}></td>
<td><{$data[out].description}></td>
<td><{section loop=$data[out].a name=in}>
<{$data[out].a[in].one}>
<{/section}></td>
</tr>
<{sectionelse}>
数组有问题
<{/section}>
b.php
<?php
include("./init.inc.php");
$tpl->assign("name","abc");
//连接数库据,产生连接对象$mysqli
$mysqli = new mysqli("localhost","root","","product");
//执行sql语句,返回结果及对象$result
$result = $mysqli->query("select * from product");
//针对二维数组
$data=array();
while($row = $result->fetch_assoc()){
$row["a"]=array(array("one"=>"aaaaaaa"),array("two"=>"bbb"));
$data[]=$row;
}
//将$row分配到模版变量里
$tpl->assign("data",$data);
//测试if条件、分配变量
$tpl->assign("val",2);
$tpl->display("a.html");
?>
演示结果:
二维数组的显示
1 | name1 | 1.02 | good1 | aaaaaaa |
2 | name2 | 1.02 | good2 | aaaaaaa |
3 | name3 | 1.01 | good3 | aaaaaaa |
4 | name4 | 1.09 | good4 | aaaaaaa |
5 | name5 | 1.08 | good5 | aaaaaaa |
6 | name6 | 1.09 | good6 | aaaaaaa |
7 | name7 | 1.05 | good7 | aaaaaaa |
8 | ?? | 50.54 | ???? | aaaaaaa |
相关文章推荐
- JNI 头文件中函数结构解析
- 解析百度图片搜索结果json中objURL图片原始地址函数(.net版 参考php版)
- 无法解析的外部符号 dll中的函数不能识别
- Python urllib的urlretrieve()函数解析
- C++ 虚函数表解析虚函数表
- 关于Oracle过程,函数的经典例子及解析
- 《写给大家看的c语言书》中所用部分函数解析
- void (*f(int, void (*)(int)))(int) 函数解析
- getopt函数解析
- 【STL】bind1st与bind2nd函数解析
- lievent 函数解析之 evutil_make_socket_nonblocking
- 解读C的声明,解析各种函数、指针组合的声明
- error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCR...
- C++中虚函数,结合例子解析,然后总结
- javascript笔记:深入了函数的作用域链及标识符解析的过程
- CImageList类Create函数参数解析
- 解析C++中的字符串处理函数和指针
- VS2012配置Opengl以及“无法解析的外部符号 __imp____glutInitWithExit@12,该符号在函数 _glutInit_ATEXIT_HACK@8 中被引用”问题
- DestroyWindow函数解析
- 函数外初始化与函数内初始化详细解析