Variables loaded from config files
Variables that are loaded from the config files are referenced by
enclosing them within hash marks (#), or with the smarty variable
$smarty.config.
The second syntax is useful for embedding into quoted attribute
values.
經由組態檔載入的變數的參照方式是將變數使用井字號(#)包圍,或是使用
Smarty 變數 $smarty.config。第二種方式在使用引號包圍屬性值時相當好用。
Example 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)
index.tpl: (另一種語法)
{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> |
this will output 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> |
|
Config file variables cannot be used until
after they are loaded in from a config file. This procedure is
explained later in this document under config_load.
組態檔變數在載入組態後才可以使用。此程序將在本文件的
config_load 後作解釋。