Get Smarty

Donate

Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Advertisement

{config_load}

{config_load} を使用して、 設定ファイル からテンプレートに #変数# を読み込みます。

属性名 必須 デフォルト 概要
file string Yes n/a インクルードする設定ファイルの名前
section string No n/a 読み込むセクションの名前
scope string no local 読み込む変数のスコープの処理方法。local、parent、global のいずれかを指定します。 local を指定すると、 変数がローカルファイルのテンプレート変数として読み込まれます。 parent を指定すると、 該当ファイルとその親ファイルのテンプレート変数として読み込まれます。 global を指定すると、すべてのテンプレートでテンプレート変数として利用できます。
global boolean No No 変数が親テンプレートから利用できるかどうか。scope=parent と同じです (注: この属性は非推奨です。代わりに scope 属性を使用するようになっていますが、 まだサポートされています。scope 属性を指定すると、この値は無視されます)。

Example 7.3. {config_load}

example.conf ファイル


# これは設定ファイルのコメントです

# グローバル変数
pageTitle = "Main Menu"
bodyBgColor = #000000
tableBgColor = #000000
rowBgColor = #00ff00

# customer 変数セクション
[Customer]
pageTitle = "Customer Info"

  

テンプレート


{config_load file="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 属性を指定する事で、そのセクション内の変数を読み込む事ができます。 セクションを指定したとしても、 グローバルな設定変数は常に読み込まれることに注意しましょう。 グローバル変数と同じ名前のセクション変数があった場合は、 セクション変数の内容が優先されます(グローバル変数の値を上書きします)。

Note

設定ファイルの sections と組み込みのテンプレート関数 {section} には特に関連はありません。単にたまたま名前が同じであるというだけのことです。

Example 7.4. セクションを指定した {config_load} 関数


{config_load file='example.conf' section='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_dirget_config_vars() および config_load() も参照してください。

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors