您当前的位置:首页 > 分类 > 技术资讯 > PHP > 正文

smarty 中fetch和display函数区别

发布时间:2015-05-28 09:17:02      来源:51推一把
【摘要】在Smarty模板函数里面有这样一个方法:fetch("template.htm"),他和display("template.htm");最大的不同就是fetch()是把内容输出给一个变量,而display()是把内容输出给浏览器,这样我们就可以用一个变量来接收fetch()的输出,然后把他写入到文件中去
在Smarty模板函数里面有这样一个方法:fetch("template.htm"),他和display("template.htm");
最大的不同就是fetch()是把内容输出给一个变量,而display()是把内容输出给浏览器,这样我们就可以用一个变量来接收fetch()的输出,然后把他写入到文件中去.

fetch() 可用于异步输出,或生成静态文件

示例:
    $ftime = time();
    $Smarty->assign(ftime,$ftime);
    $content=$Smarty->fetch($root.test.html);
    $filename=/html/test.shtml;
    if(file_exists($filename)) unlink($filename);
    $fp=fopen($filename,w);
    fwrite($fp,$content);
    fclose($fp);

//直接显示到浏览器
    $Smarty->display(test.html);