天天看點

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是必須的屬性,上面的寫法估計不嚴謹,簡單記錄一下吧。