config_load :加载配置文件
file= “配置文件名称”
section=“区域名称”
$tpl->configs=”./configs” //基准路径
./configs/dir_1/a.conf
<{config_load file=” dir_1/a.conf” section=“one” }>
include :
标签用于在当前模板中包含其它子模板.
当前模板中的变量在被包含的子模板中可用
<{include file=”header.tpl”}>
<{include file=”footer.html”}>
捕获模板输出的数据并将其存储到一个变量里,而不是把它们输出到页面.
任何在 {capture name="foo"}和{/capture}之间的数据将被存储到变量$foo中,该变量由name属性指定.
在模板中通过 $smarty.capture.foo 访问该变量.
如果没有指定 name 属性,函数默认将使用 "default" 作为参数.
{capture}必须成对出现,即以{/capture}作为结尾,该函数不能嵌套使用.
<{capture name=”自定义区域名”}>
aAaaaaaaaaaaaaa
<{$name}>
<{include file=”head.tpl”}>
……
<{/capture}>
<{$smarty.capture.自定义区域名}>
<br><br>
演示嵌套foreach循环的使用<br>
<table border="2">
<{foreach from=$data item=row name=out}>
<{if $smarty.foreach.out.first}>
<tr bgcolor="red">
<{elseif $smarty.foreach.out.last}>
<tr bgcolor="green">
<{/if}>
<{foreach from=$row item=col name=in}>
<td><{$col}></td>
<{foreachelse}>
该数据有问题
<{/foreach}>
</tr>
<{foreachelse}>
该数据有问题 <{/foreach}>
外层循环共计<{$smarty.foreach.out.total}>次<br>
内层循环共计<{$smarty.foreach.in.total}>次
</table>
功能和语法与php当中类似,====foreach
foreach($row as $key=>$value){
…
}
效率差;
for($i=0;$i<5;$i++){ }
变量
$smarty.foreach.循环名.变量名
iteration :用于显示当前循环的执行次数,从1开始,每执行一次增加 1
section,sectionelse (推荐)for
功能和效率要比foreach好
只针对索引数组
section 显示二维数组 loop
section 不能处理下标不连续的数组
<br><br>
演示section循环的使用<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}>
</td>
</tr>
<{sectionelse}>
该数组有问题
<{/section}>
<{/section}>
</table>
<br><br>
if结构的使用:<br>
<{if $val is even}>
aaaaaaaaaaaaa<br>
<{elseif $val==2}>
ccccccccccccc
<{else}>
bbbbbbbbbbbbb<br>
<{/if}>
<br><br>
eq(相等)、ne(不等)、neq(不等)、gt
(大于)、lt(小于)、lte(小于等于)、le(小于等于)、gte(大于等于)、ge(大于等于)、
>、<、<=、>=.==、!=、
is even、is odd、is not even、is not odd、not、mod、div by、even by、odd by、