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} dipakai untuk mengambil #variables# konfig dari file konfigurasi ke dalam template.

Attribute NameTypeRequiredDefaultDescription
filestringYesn/aNama file config untuk disertakan
sectionstringNon/aNama seksi untuk diambil
scopestringnolokal Bagaimana lingkup variabel yang diambil diperlakukan, yang harus berupa lokal, parent atau global. Lokal berarti variabel diambil ke dalam konteks template lokal. parent berarti variabel diambil ke dalam konteks lokal dan template leluhur yang memanggilnya. global berarti variabel tersedia bagi seluruh template.
globalbooleanNoNo Apakah variabel terlihat ke template leluhurnya atau tidak, sama seperti scope=parent. CATATAN: Atribut ini tidak dipakai lagi oleh atribut scope, tapi masih didukugn. Jika scope disertakan, nilai ini diabaikan.

Teladan 7-3. {config_load}

File example.conf.

#ini komentar file config

# variabel global
pageTitle = "Main Menu"
bodyBgColor = #000000
tableBgColor = #000000
rowBgColor = #00ff00

#seksi variabel kustomer
[Customer]
pageTitle = "Customer Info"

dan template

{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>

File Config dapat juga berisi seksi. Anda bisa mengambil variabel dari dalam seksi dengan menambahkan atribut section. Catatan bahwa variabel config global selalu diambil bersamaan dengan variabel seksi, dan variabel seksi bernama-sama menimpa global.

Catatan: Seksi file config dan fungsi template built-in memanggil {section} tidak ada kaitannya dengan yang lain, itu terjadi untuk berbagi konvensi penamaan umum.

Teladan 7-4. function {config_load} dengan seksi

{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>

Lihat $config_overwrite untuk membuat arrays dari variabel file config.

Lihat juga halaman config files, halaman config variables, $config_dir, get_config_vars() dan config_load().

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors