configLoad('test.conf')則只使用全局的">

jizzjizz欧美69巨大,18禁网站点击进入在线,美女兔女郎粉逼被操网站,欧美精品区一区二区三区

首頁 > 職業(yè)資格  > 

利用PHP引擎smarty(3)

2022-12-30   來源:萬能知識網

利用PHP模板引擎smarty


(資料圖片)

#$sections參數(shù)可以不寫,默認值為null,$smarty->configLoad("test.conf")則只使用全局的鍵值,而不能使用標簽下的鍵值

#在模版下通過{config_load file="test.conf" section="china" scope="global"}語句調用配置文件

#section屬性可以不寫,默認是null,scope屬性必須寫{config_load file="test.conf" scope="global"}

#section屬性可賦三種值

#local 只有當前模版可以使用該配置文件

#parent 只有當前模版引入該配置文件語句后包含的模版中,或在php源文件中smarty對象調用該配置文件后調用的模版中可以使用該配置文件中的鍵值

#global 測試效果和parent相同

#在模版中通過{#language#}來使用鍵值,也可以通過{$smarty.config.language}來訪問配置文件鍵值

#PHP源文件中可以使用$smarty->getConfigVars("language")或$smarty->getConfigVariable("language")來獲取鍵值,$smarty->getConfigVars("language")獲取的還可能是數(shù)組

*/

/*

tpl文件中常用函數(shù)

tpl文件:

{capture name="testCapture"}

{include file="f1.tpl"}

{/capture}

{if true}

{$smarty.capture.testCapture}

{/if}

{if $name == "wang"}

Welcome wang.

{elseif $name == "zhang"}

Welcome zhang.

{else}

Welcome, whatever you are.

{/if}

{*操作符可以是 ==,>= 等也可以是 eq,ne等*}

{for $x=0; $x

{$x}

{/for}

{*for循環(huán),類似PHP代碼*}

{$x=0}

{while $x

{$x++}

{/while}

{*While循環(huán),也類似PHP代碼。*}

{foreach name="testForeach" from=$testArr key=arId item=arVal}

{$arId}對應的值為:{$arVal}

{$smarty.foreach.testForeach.index} ?

{$smarty.foreach.testForeach.iteration} ?

{$smarty.foreach.testForeach.first}

{$smarty.foreach.testForeach.last}

{$smarty.foreach.testForeach.total}

{foreachelse}

$testArr is null

{/foreach}

{*也可以如下兩種類PHP格式*}

{foreach $testArr as $n}

{$n}

{/foreach}

{foreach $testArr as $key=>$n}

{$key}

{/foreach}

{$sectionArr = [0=>"a",4=>"b","c","d","e",6,7,8,9,10,11,12,13,14,15,16]}

{section name="testSection" loop=$sectionArr start=0 step=4 max=6 show=true}

{$smarty.section.testSection.index}-

{$sectionArr[testSection]}-

{$smarty.section.testSection.iteration}-

{sectionelse}

$sectionArr is null

{/section}

*/

/*

tpl模板文件:

{literal}

script type="text/javascript"

function a(){

alert("this is script");

}

a();

/script

詞條內容僅供參考,如果您需要解決具體問題
(尤其在法律、醫(yī)學等領域),建議您咨詢相關領域專業(yè)人士。

標簽

配置文件

推薦詞條

都安| 湟中县| 沾化县| 舒城县| 根河市| 秀山| 琼海市| 安达市| 西吉县| 澄迈县| 晋中市| 聊城市| 上思县| 陕西省| 阿荣旗| 抚顺市| 农安县| 肇东市| 霍林郭勒市| 彭泽县| 临沂市| 五莲县| 莱阳市| 临海市| 苏尼特右旗| 赣州市| 顺昌县| 东乌珠穆沁旗| 上饶县| 萍乡市| 宽城| 丰顺县| 泗水县| 涿州市| 叙永县| 孟村| 启东市| 鄄城县| 河池市| 华阴市| 尖扎县|