跳到内容

{config_load}

{config_load} 用于从 配置文件 中加载配置文件 #variables# 到模板中。

属性

属性名称 必需项 说明
文件 包含的配置文件名称
部分 加载的部分名称

示例

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 属性能从部分中加载变量。请注意,全局配置文件变量总是随部分变量一起加载,同名部分变量会覆盖全局变量。

注意

配置文件部分 和名为 {section} 的内置模板函数没有关联,它们碰巧采用了相同的命名约定而已。

{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_overwrite 以创建配置文件变量数组。

另请参见 配置文件 页面、配置变量 页面、$config_dirgetConfigVars()configLoad()