smarty自定義函數

 內建函數:smarty自帶 ,不能修改

  自定義函數:可以自行修改

              保存在plugins目錄下

              語法格式類似於html標記的寫法

              <{……}>

一、瞭解smarty自定義函數

  例如:

1)  smarty自定義函數assign

作用:用於在模板被執行時爲模板變量賦值.

函數名稱:assign

參數:var:   聲明變量名稱  字符串

      Value: 給該變量賦值  字符串

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

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

<input  type=”text”  name=”input1”>

 屬性無順序要求

<{config_load  file=”*.conf”  section=”one”}> 

2)  smarty方法assign  

二、實現自定義函數

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

第二步:打開文件

    Function smarty_block_hello($args,$content,&$smarty){..}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章