{eval}
{eval} は、与えられた変数をテンプレートとして評価します。
テンプレート変数又はテンプレートタグを
変数や設定ファイル内に埋め込むような用途に使われます。
assign 属性が指定されると、
{eval} 関数の出y録はこのテンプレート変数に割り当てられ、
テンプレートに出力されることはありません。
例 8-6. {eval} 設定ファイル setup.conf emphstart = <strong>
emphend = </strong>
title = Welcome to {$company}'s home page!
ErrorCity = You must supply a {#emphstart#}city{#emphend#}.
ErrorState = You must supply a {#emphstart#}state{#emphend#}. |
テンプレート
{config_load file='setup.conf'}
{eval var=$foo}
{eval var=#title#}
{eval var=#ErrorCity#}
{eval var=#ErrorState# assign='state_error'}
{$state_error} |
上のテンプレートの出力
This is the contents of foo.
Welcome to Foobar Pub & Grill's home page!
You must supply a <strong>city</strong>.
You must supply a <strong>state</strong>. |
|
例 8-7. もうひとつの {eval} の例 これは、サーバ名 (大文字変換したもの) と IP を出力します。
割り当てられる変数 $str は、
データベースのクエリから取得します。
<?php $str = 'The server name is {$smarty.server.SERVER_NAME|upper} ' .'at {$smarty.server.SERVER_ADDR}'; $smarty->assign('foo',$str); ?>
|
テンプレート
|