Smarty-核心思想

fetch 和 display的区别

display == echo fetch;

传值,渲染页面

$a = '123';
$sm->assign('a', $a);
$sm->display('index.php');

开启缓存

$sm = new Smarty();
$sm->caching = true;
$sm->cache_lifetime = 9;

判断缓存

$sm->isCached('index.php');
返回值:boolean;

单模板多缓存


        $sm->isCached('index.php', $id);
        $sm->assign('id', $id);
        $sm->display('index.php');

类似的代码会对一个模板针对不同的id值进行多个缓存文件

局部缓存

$sm->assign('foo' $foo, true);  //第三个参数设为true,表示不缓存

大段代码不缓存时用{nocache}{/nocache}标签包起来,例如:

{nocache}
	{$smarty.now}
{/nocache}

猜你喜欢

转载自blog.csdn.net/Wake_me_Up123/article/details/84565916