跳至内容

{append}

{append} 用于在执行模板期间创建或追加模板变量数组。

属性

属性 必需 说明
var 要分配的变量的名称
value 要分配的值
index (可选) 新数组元素的索引。如果未指定,该值将追加到数组末尾。
scope (可选) 已分配变量的作用域:父级、根级或全局。如果省略,则默认为本地。

选项标志

名称 说明
nocache 使用“nocache”属性分配变量

注意

模板中变量的分配实质上是将应用程序逻辑置入演示中,而该逻辑可能在 PHP 中会得到更好的处理。请自行斟酌使用。

示例

{append var='name' value='Bob' index='first'}
{append var='name' value='Meyer' index='last'}
// or 
{append 'name' 'Bob' index='first'} {* short-hand *}
{append 'name' 'Meyer' index='last'} {* short-hand *}

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()