{config_load}用于从配置文件中
加载配置变量#variables#。
属性:
| 参数名称 | 类型 | 必选参数 | 默认值 | 说明 |
|---|---|---|---|---|
| file | string | Yes | n/a | 载入的配置文件名 |
| section | string | No | n/a | 指定载入配置变量的段落 |
| scope | string | no | local | 配置变量的作用范围,取值local, parent 或 global. local表示变量只能在当前模板的上下文中使用。 parent表示变量可以在当前模板和父模板使用。 global表示变量在任何地方都可用。 |
Example 7.24. {config_load}
example.conf 配置文件.
#this is config file comment # global variables pageTitle = "Main Menu" bodyBgColor = #000000 tableBgColor = #000000 rowBgColor = #00ff00 #customer variables section [Customer] pageTitle = "Customer Info"
模板是:
{config_load file="example.conf"}
{config_load "example.conf"} {* short-hand *}
<html>
<title>{#pageTitle#|default:"No title"}</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>
配置文件
可能会有一些段落。你可以用section属性单独载入某个指定段落的配置变量。
注意全局的配置变量会同时被载入,同名的段落配置变量会覆盖全局的配置变量。
配置文件的sections和内置函数{section}是不相关的,它们只是刚好名称比较像。
Example 7.25. {config_load} 载入段落配置变量
{config_load file='example.conf' section='Customer'}
{config_load 'example.conf' 'Customer'} {* short-hand *}
<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>
参见配置文件,
配置变量,
$config_dir,
getConfigVars()
和
configLoad().