![]() |
|
首页 │ Apache │ Linux│ Java│ MySQL│ 注册│帮助 | |||
smarty_manual 关于capture 的说明是这样的:
capture函数的作用是收集模板输出的数据到一个变量里,而不是把它们输出到页面.
任何在 {capture name="foo"}和{/capture}之间的数据都被收到了由函数的名称属性指定的变量里($foo).
收集的信息可以用在特殊变量$smarty里.
例如capture.foo就收集了以上数据.如果函数没有名字属性,将使用"default".
每个{capture}都必须对应{/capture},也不能嵌套使用capture函数
我写了一个如下的使用,得到的结果却不是我想要的。
---------
{$capture name="ca1"}
{$what}
{/capture}
{if $smarty.capture.cal eq "hello"}
{$successful}
{else}
{$faild}
{/if}
---
<?php
require_once('../libs/smarty.class.php');
$smarty=new smarty();
$smarty->assign('what', 'hello');
$smarty->assign('successful', 'hahahahahahahah');
$smarty->assign('faild', 'wwwwwwwwwwwwwwwwwwwwwwwww');
$smarty->display('capture.tpl');
?>
我以为只输出hahahhahahahahah.
但是却输出了:hello wwwwwwwwwwwwwwwwwwwwwwwww
请高手指教!!

