Smarty生成静态页面的方法

<?php  
/* 
 *Smarty生成静态页面 
 *Smarty生成静态页面的条件 
 *调用Smarty类及配置相关属性 
 *使用fetch()方法实现生成静态页面 
 */  
  
//调用Smarty类  
include("smarty/smarty.class.php");  
  
//实例化Smarty和配置Smarty属性  
$smarty = new Smarty();    //实例化Smarty对象  
$smarty->template_dir = "smarty/templates";    //模板文件的目录  
$smarty->compile_dir = "smarty/template_c";    //编译的模板文件  
$smarty->config_dir = "smarty/configs";        //配置文件目录  
$smarty->cache_dir = "smarty/cache";           //缓存的所有文件  
$smarty->caching = false;  
$smarty->left_delimiter = "<{";  
$smarty->right_delimiter = "}>";  
  
//Smarty生成静态页面的代码  
$smarty->assign("contect", "HelloWorld!");  
$contect = $smarty->fetch("index.tpl");  
$fp = fopen("index.html", "w");  
fwrite($fp, $contect);  
fclose($fp)  
?>  
  
//index.tpl模版  
<html>  
<head>  
<title>Test</title>  
</head>  
<body>  
<{$contect}>  
</body>  
</html>  
  
//生成后的index.html  
<html>  
<head>  
<title>Test</title>  
</head>  
<body>  
HelloWorld!  
</body>  
</html>  

转:http://blog.csdn.net/l_phper/article/details/4851802

原文地址:https://www.cnblogs.com/shuaixf/p/2658613.html