課堂筆記!

 

自定義函數

  爲了擴展功能,根據實際需求進行編輯

自定義標籤

   <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

first :

last 

show 

total 

section,sectionelse   (推薦)for

   功能和效率要比foreach好

   只針對索引數組

   section 顯示二維數組 loop

   section 不能處理下標不連續的數組

     

if,elseif,else 

eq(相等)、ne(不等)、neq(不等)、gt

(大於)、lt(小於)、lte(小於等於)、le(小於等於)、gte(大於等於)、ge(大於等於)、><<=>=.==!=

is evenis oddis not evenis not oddnotmoddiv byeven byodd by

strip 

include_php 

insert 

php 

ldelim,rdelim 

literal 

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