在smarty中有一个获取模板页内容方法fetch(), 它的声明原形为:
<?php  
    function fetch(  
      $resource_name,  
      $cache_id=null,  
      $compile_id=null,  
      $display=false)  
?>
代码说明:
第一个参数为模板名称, 第二个参数为缓存的id, 第三个参数为编译id, 第四个参数为是否显示模板内容。
生成静态页,就需要用到这个方法。
<?php  
   $smarty= newSmarty(); 
    //其它模板替换语法…  
    //取得页面中所有内容, 注意最后一个参数为false  
   $content=$smarty->fetch(’模板名称.tpl’, null, null, false);  
    //将内容写入至一个静态文件 
    $fp=fopen(’news.html’,'w’);  
   fwrite($fp,$content); 
    fclose($fp); 
//by www.jb200.com
?>
这样,就生成了静态页面news.html。