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:
{append}
は、テンプレート変数の配列を
テンプレートの実行時に
作成あるいは追加します。
テンプレート内で変数に代入するというのは、 本質的にはアプリケーションのロジックをプレゼンテーションに持ち込んでいることになります。 これは本来 PHP 側でやったほうがうまく処理できることでしょう。 自己責任のもとで使いましょう。
属性
属性名 | 型 | 必須 | デフォルト | 概要 |
---|---|---|---|---|
var | string | Yes | n/a | 代入される変数の名前 |
value | string | Yes | n/a | 代入される値 |
index | string | No | n/a | 新しい配列要素の添え字。 省略した場合は配列の最後の要素として値が追加されます |
scope | string | No | n/a | 代入する変数のスコープ。'parent'、'root' あるいは 'global' |
オプションのフラグ
名前 | 概要 |
---|---|
nocache | 変数を 'nocache' 属性つきで代入する |
Example 7.7. {append}
{append var='name' value='Bob' index='first'} {append var='name' value='Meyer' index='last'} // あるいは {append 'name' 'Bob' index='first'} {* 短縮形 *} {append 'name' 'Meyer' index='last'} {* 短縮形 *} The first name is {$name.first}.<br> The last name is {$name.last}.
上の例の出力は次のようになります。
The first name is Bob. The last name is Meyer.
append()
および
getTemplateVars()
も参照ください。