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

strip

include_php

insert

php

ldelim,rdelim

literal
發佈了69 篇原創文章 · 獲贊 73 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章