smarty函数扩展

 

  内建函数与自定义函数的不同:

  内建函数:smarty自带 ,不能修改

  自定义函数:可以自行修改

              保存在plugins目录下

              语法格式类似于html标记的写法

              <{……}>

了解smarty自定义函数

 例如:

   1smarty自定义函数assign

      作用:用于在模板被执行时为模板变量赋值.

      函数名称:assign

      参数:var:   声明变量名称  字符串

      Value: 给该变量赋值  字符串

<{assign  var=”title”  value=”this is title”}>

   $tpl->assign(“title”,”this is title”);

实现自定义函数

1)例如:

a.html  

<{title  num=”10”  content=”aaaa”  size=”10”  color=”red”  }>

b.php

第一步:自定义函数

function  fun1(){}

第二步:注册自定义函数

$tpl->register_function(“模板文件中的函数名”,”php中的函数名”)

Plugins/function_自定义函数名_*

3.* 版本不支持

2) 注册块

   $tpl->register_block(“模板文件中的块名”,”php中的函数名”)

           <hr />

<br /> 

<a> </a>

a.html

          <{h   num=10  content=”aaa”}>

          <{/h}>   

3) 在plugins目录下新建文件

新建函数文件 world

  例如:

function.assign_debug_info.php

function  smarty_function_***(){}

  步骤

第一步:plugins下新建文件function.world.php

第二步:打开文件

    Function smarty_function_world($args,&$smarty){..}

                新建块文件hello(文件名自定)

block.hello.php

function  smarty_block_hello(){}

第一步:plugins下新建块文件block.hello.php

第二步:打开文件

           

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值