Files
smarty/docs/ja/designers/language-builtin-functions/language-function-config-load.xml
2007-05-03 22:32:22 +00:00

188 lines
5.8 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 1.13 Maintainer: takagi Status: ready -->
<!-- CREDITS: mat-sh,daichi,joe -->
<sect1 id="language.function.config.load">
<title>{config_load}</title>
<para>
<varname>{config_load}</varname> を使用して、
<link linkend="config.files">設定ファイル</link> からテンプレートに
<link linkend="language.config.variables"><parameter>#変数#</parameter></link>
を読み込みます。
</para>
<informaltable frame="all">
<tgroup cols="5">
<colspec colname="param" align="center" />
<colspec colname="type" align="center" />
<colspec colname="required" align="center" />
<colspec colname="default" align="center" />
<colspec colname="desc" />
<thead>
<row>
<entry>属性名</entry>
<entry></entry>
<entry>必須</entry>
<entry>デフォルト</entry>
<entry>概要</entry>
</row>
</thead>
<tbody>
<row>
<entry>file</entry>
<entry>string</entry>
<entry>Yes</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>インクルードする設定ファイルの名前</entry>
</row>
<row>
<entry>section</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>読み込むセクションの名前</entry>
</row>
<row>
<entry>scope</entry>
<entry>string</entry>
<entry>no</entry>
<entry><emphasis>local</emphasis></entry>
<entry>
読み込む変数のスコープの処理方法。local、parent、global
のいずれかを指定します。 local を指定すると、
変数がローカルファイルのテンプレート変数として読み込まれます。 parent を指定すると、
該当ファイルとその親ファイルのテンプレート変数として読み込まれます。
global を指定すると、すべてのテンプレートでテンプレート変数として利用できます。
</entry>
</row>
<row>
<entry>global</entry>
<entry>boolean</entry>
<entry>No</entry>
<entry><emphasis>No</emphasis></entry>
<entry>
変数が親テンプレートから利用できるかどうか。scope=parent と同じです
(注: この属性は非推奨です。代わりに scope 属性を使用するようになっていますが、
まだサポートされています。scope 属性を指定すると、この値は無視されます)。
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<example>
<title>{config_load}</title>
<para>
<filename>example.conf</filename> ファイル
</para>
<programlisting>
<![CDATA[
# これは設定ファイルのコメントです
# グローバル変数
pageTitle = "Main Menu"
bodyBgColor = #000000
tableBgColor = #000000
rowBgColor = #00ff00
# customer 変数セクション
[Customer]
pageTitle = "Customer Info"
]]>
</programlisting>
<para>テンプレート</para>
<programlisting>
<![CDATA[
{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>
]]>
</programlisting>
</example>
<para>
<link linkend="config.files">設定ファイル</link>
には、セクションも含まれます。<parameter>section</parameter>
属性を指定する事で、そのセクション内の変数を読み込む事ができます。
セクションを指定したとしても、
グローバルな設定変数は常に読み込まれることに注意しましょう。
グローバル変数と同じ名前のセクション変数があった場合は、
セクション変数の内容が優先されます(グローバル変数の値を上書きします)。
</para>
<note>
<para>
設定ファイルの <emphasis>sections</emphasis> と組み込みのテンプレート関数
<link linkend="language.function.section"><varname>{section}</varname></link>
には特に関連はありません。単にたまたま名前が同じであるというだけのことです。
</para>
</note>
<example>
<title>セクションを指定した {config_load} 関数</title>
<programlisting>
<![CDATA[
{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>
]]>
</programlisting>
</example>
<para>
設定ファイル変数の配列については
<link linkend="variable.config.overwrite"><parameter>$config_overwrite</parameter></link>
を参照してください。
</para>
<para>
<link linkend="config.files">設定ファイル</link> のページ、
<link linkend="language.config.variables">config 変数</link> のページ、
<link linkend="variable.config.dir"><parameter>$config_dir</parameter></link>
<link linkend="api.get.config.vars"><varname>get_config_vars()</varname></link>
および
<link linkend="api.config.load"><varname>config_load()</varname></link>
も参照してください。
</para>
</sect1>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->