天天看点

smarty capture使用

smarty内置函数capture用法分析

{capture}可以捕获标记范围内的输出内容,并存到变量中而不显示。有三种用法,

代码如下:

复制代码 代码如下:

{capture name="banner"}aaaaaa{/capture}

{$smarty.capture.banner}

{capture assign="foo"}bbbbbb{/capture}

{$foo}

{capture append="arr"}hello{/capture}

{capture append="arr"}world{/capture}

{foreach $arr as $value}

{$value}

{/foreach}

第一种:{capture}使用name属性;

第二种:{capture}捕获内容到变量;

第三种:{capture}捕获内容到数组变量。

转载自 http://www.php.cn/php-notebook-167408.html

补充,看了下手册,name是必须的属性,上面的写法估计不严谨,简单记录一下吧。