{assign} {assign} は、テンプレート変数を テンプレートの実行時に 割り当てます。 属性名 必須 デフォルト 概要 var string Yes n/a 割り当てられるテンプレート変数の名前 value string Yes n/a テンプレート変数に割り当てる値 {assign} 上の例の出力 {assign} での演算子の使用 この複雑な例では、変数を `バッククォート` で囲む必要があります。 PHP スクリプトからの {assign} 変数へのアクセス PHP スクリプトから {assign} 変数にアクセスするには get_template_vars() を使用します。これは、変数 $foo を作成するテンプレートです。 テンプレート変数は、以下のスクリプトのように テンプレートの実行後か実行中にしか利用できません。 get_template_vars('foo'); // テンプレートを変数に格納します。 $whole_page = $smarty->fetch('index.tpl'); // これは 'smarty' と出力します。テンプレートが実行されたからです。 echo $smarty->get_template_vars('foo'); $smarty->assign('foo','Even smarter'); // これは 'Even smarter' を出力します。 echo $smarty->get_template_vars('foo'); ?> ]]> 次の関数も、オプションで テンプレート変数へ割り当てることができます。 {capture}{include}{include_php}{insert}{counter}{cycle}{eval}{fetch}{math}{textformat} assign() および get_template_vars() も参照してください。