内建函数

来源:互联网 发布:数据保密协议pdf 编辑:程序博客网 时间:2024/05/22 07:44

自定义函数

  为了扩展功能,根据实际需求进行编辑

自定义标签

  <input type=text  name=”input1”>

<{title  num=”10”content=”aaa” size=…}>

1)  PHP文件

Function  fun1($args){……}

$tpl->register_function(“tilte”’,”fun1”);

2)./plugins/function.模板文件函数名.php

     Function smarty_function_**($args,&$smarty){…..}

 

  <a> </a>

   <{title  num=”10”  size=…}> 111111<{/title}>

1)    PHP文件

Function  fun1($args,$content){……}

$tpl->register_block(“tilte”’,”fun1”);

2)./plugins/block.模板文件函数名.php

     Function smarty_block_**($args,$content,&$smarty){…..}

内建函数

   按照smarty的要求去用

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

  捕获模板输出的数据并将其存储到一个变量里,而不是把它们输出到页面.

  任何在 {capture name="foo"}和{/capture}之间的数据将被存储到变量$foo中,该变量由name属性指定.
在模板中通过 $smarty.capture.foo访问该变量.
如果没有指定 name 属性,函数默认将使用 "default" 作为参数.
{capture}必须成对出现,即以{/capture}作为结尾,该函数不能嵌套使用.

 

<{capture name=”自定义区域名”}>

aAaaaaaaaaaaaaa

<{$name}>

<{include  file=”head.tpl”}>

……

<{/capture}>

 

<{$smarty.capture.自定义区域名}>

 

foreach,foreachelse

  功能和语法与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 不能处理下标不连续的数组



原创粉丝点击