What is Smarty?
Why use it?
Use Cases and Work Flow
Syntax Comparison
Template Inheritance
Best Practices
Crash Course
You may use the Smarty logo according to the trademark notice.
For sponsorship, advertising, news or other inquiries, contact us at:
設定ファイル
から読み込まれた変数を参照するには、それをハッシュマーク (#
)
で囲むか、あるいは Smarty 変数
$smarty.config
を使用します。
2つ目の方法は、クォートされた属性値の中に含める場合に便利です。
Example 4.6. 設定ファイルの変数
サンプルの設定ファイル - foo.conf
:
pageTitle = "This is mine" bodyBgColor = '#eeeeee' tableBorderSize = 3 tableBgColor = "#bbbbbb" rowBgColor = "#cccccc"
#hash#
方式のテンプレート
{config_load file='foo.conf'} <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>
$smarty.config
方式のテンプレート
{config_load file='foo.conf'} <html> <title>{$smarty.config.pageTitle}</title> <body bgcolor="{$smarty.config.bodyBgColor}"> <table border="{$smarty.config.tableBorderSize}" bgcolor="{$smarty.config.tableBgColor}"> <tr bgcolor="{$smarty.config.rowBgColor}"> <td>First</td> <td>Last</td> <td>Address</td> </tr> </table> </body> </html>
どちらの場合も出力は同じです。
<html> <title>This is mine</title> <body bgcolor="#eeeeee"> <table border="3" bgcolor="#bbbbbb"> <tr bgcolor="#cccccc"> <td>First</td> <td>Last</td> <td>Address</td> </tr> </table> </body> </html>
変数は、設定ファイルから読み込まれるまで使用できません。
詳細は、後ほど
{config_load}
の項で説明します。
変数 および 予約変数 $smarty も参照してください。