codecamp

Smarty:append函数

{append}

{append}可以在 运行时 为数组变量增加或者创建值。

温馨提示:

这需要考虑的是,对于模板中变量的赋值,最好尽量是放到PHP程序代码中进行。

属性:

参数名称类型必选参数默认值说明
varstringYesn/a赋值的变量名称
valuestringYesn/a赋予的值
indexstringNon/a数组元素的新索引,如果没有提供此参数,则附加的值会加到数组最后。
scopestringNon/a赋值变量的访问范围: 'parent','root' 或 'global'

可选的标记:

名称说明
nocache为变量增加'nocache'属性

Example 7.7. {append}

{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.

Smarty:var函数
Smarty:assign函数
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定