{config_load}
{config_load} 用于从配置文件加载配置#variables#到模板中。
属性
| 属性名称 | 是否必须 | 描述 |
|---|---|---|
| file | 是 | 要包含的配置文件的名称 |
| section | 否 | 要加载的部分的名称 |
| scope | 否 | 加载的变量的作用域处理方式,必须是 local,parent 或 global 之一。local 表示将变量加载到本地模板上下文中。parent 表示将变量加载到本地上下文和调用它的父模板中。global 表示变量对所有模板可用。 |
示例
example.conf 文件。
#这是配置文件注释
# 全局变量
pageTitle = "主菜单"
bodyBgColor = #000000
tableBgColor = #000000
rowBgColor = #00ff00
#客户变量部分
[Customer]
pageTitle = "客户信息"
以及模板
{config_load file="example.conf"}
{config_load "example.conf"} {* 简写 *}
<html>
<title>{#pageTitle#|default:"无标题"}</title>
<body bgcolor="{#bodyBgColor#}">
<table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}">
<tr bgcolor="{#rowBgColor#}">
<td>姓</td>
<td>名</td>
<td>地址</td>
</tr>
</table>
</body>
</html>
配置文件也可以包含部分。你可以使用附加的属性 section 从部分中加载变量。注意,全局配置变量总是与部分变量一起加载,同名的部分变量会覆盖全局变量。
注意
配置文件的部分和内置的模板函数
{section}没有任何关系,它们只是恰好共享了一个命名规则。
{config_load file='example.conf' section='Customer'}
{config_load 'example.conf' 'Customer'} {* 简写 *}
<html>
<title>{#pageTitle#}</title>
<body bgcolor="{#bodyBgColor#}">
<table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}">
<tr bgcolor="{#rowBgColor#}">
<td>姓</td>
<td>名</td>
<td>地址</td>
</tr>
</table>
</body>
</html>
参见 $config_overwrite 来创建配置文件变量的数组。
另请参见 配置文件 页面,配置变量 页面,
$config_dir,
getConfigVars() 和
configLoad()。