{config_load} を使用して、
設定ファイル からテンプレートに
#変数#
を読み込みます。
属性
| 属性名 | 型 | 必須 | デフォルト | 概要 |
|---|---|---|---|---|
| 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 ファイル
# これは設定ファイルのコメントです # グローバル変数 pageTitle = "Main Menu" bodyBgColor = #000000 tableBgColor = #000000 rowBgColor = #00ff00 # customer 変数セクション [Customer] pageTitle = "Customer Info"
テンプレート
{config_load file="example.conf"}
{config_load "example.conf"} {* 短縮形 *}
<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'} {* 短縮形 *}
<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 変数 のページ、
$config_dir、
get_config_vars()
および
config_load()
も参照してください。