鍍金池/ 教程/ PHP/ Smarty從配置文件讀取的變量
Smarty安裝
Smarty insert
Smarty 建立緩存
Smarty調(diào)試控制臺
Smarty if,elseif,else
Smarty include_php
Smarty多個(gè)緩存
Smarty方法
Smarty section,sectionelse
Smarty注釋代碼
Smarty屬性
Smarty緩沖處理函數(shù)
Smarty變量調(diào)節(jié)器
Smarty函數(shù)
Smarty組合修改器
Smarty雙引號里值的嵌入
Smarty預(yù)過濾器
Smarty foreach,foreachelse
Smarty include
Smarty Caching緩存
Smarty變量
Smarty assign用法
Smarty控制插件輸出緩沖
Smarty從配置文件讀取的變量
Smarty對象
Smarty literal
Smarty緩存集合
Smarty教程
Smarty display方法
Smarty自定義函數(shù)
Smarty配置文件
Smarty擴(kuò)展設(shè)置
Smarty數(shù)學(xué)運(yùn)算
Smarty輸出濾鏡
Smarty fetch方法

Smarty從配置文件讀取的變量

從配置文件讀取的變量

配置文件中的變量需要通過用兩個(gè)"#"或者是smarty的保留變量 $smarty.config.來調(diào)用(下節(jié)將講到)
第二種語法在變量作為屬性值并被引號括住的時(shí)候非常有用.
(譯注:舉個(gè)例子 {include file="#includefile#"} 這樣#includefile#將被當(dāng)作字符處理,而不表示配置文件變量,
    但可以這樣表示 {include file="`$smarty.config.includefile`"}不要忘了加``)


例 4-5.從配置文件引用的變量

foo.conf:

pageTitle = "This is mine"
bodyBgColor = "#eeeeee"
tableBorderSize = "3"
tableBgColor = "#bbbbbb"
rowBgColor = "#cccccc"

index.tpl:

{config_load file="foo.conf"}
<html>
<title>{#pageTitle#}</title>
<body bgcolor="{#bodyBgColor#}">
<table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}">
<tr bgcolor="{#rowBgColor#}">
	<td>First</td>
	<td>Last</td>
	<td>Address</td>
</tr>
</table>
</body>
</html>

index.tpl: (alternate syntax)

{config_load file="foo.conf"}
<html>
<title>{$smarty.config.pageTitle}</title>
<body bgcolor="{$smarty.config.bodyBgColor}">
<table border="{$smarty.config.tableBorderSize}" bgcolor="{$smarty.config.tableBgColor}">
<tr bgcolor="{$smarty.config.rowBgColor}">
	<td>First</td>
	<td>Last</td>
	<td>Address</td>
</tr>
</table>
</body>
</html>


OUTPUT: (same for both examples)

<html>
<title>This is mine</title>
<body bgcolor="#eeeeee">
<table border="3" bgcolor="#bbbbbb">
<tr bgcolor="#cccccc">
	<td>First</td>
	<td>Last</td>
	<td>Address</td>
</tr>
</table>
</body>
</html>

 

配置文件的變量只有在它們被加載以后才能使用.
這個(gè)過程將在以后 {config_load} . 的章節(jié)里說明.


上一篇:Smarty對象下一篇:Smarty預(yù)過濾器