异想天开

What's the true meaning of light, Could you tell me why

smarty模板学习

日期:2015-05-27 20:34:54
  
最后更新日期:2015-05-27 20:36:18
smarty模板比较古老,我的站点也是利用smarty来进行页面静态化。
[code lang="cpp"]
ini_set('date.timezone','Asia/Shanghai');
error_reporting(7);
define('BASE_PATH',"/usr/local/src/web/test/");
define('SMARTY_PATH',"Smarty-3.1.14/");
include_once( BASE_PATH.SMARTY_PATH."libs/Smarty.class.php"); //包含smarty类文件
$smarty = new Smarty(); //建立smarty实例对象$smarty
$smarty->template_dir = "/usr/local/src/man1/"; //设置模板目录
$smarty->compile_dir = BASE_PATH."templates_c"; //设置编译目录
$smarty->cache_dir = BASE_PATH."cache"; //缓存目录
$smarty->cache_lifetime = 600; //缓存时间
$smarty->config_dir = BASE_PATH."configs";
$smarty->caching = false; //缓存方式

$smarty->left_delimiter = "{%";
$smarty->right_delimiter = "%}";
$smarty->assign("SiteName", $title); //进行模板变量替换
$smarty->assign("Title", $title); //进行模板变量替换
$smarty->assign("Content", $content);
$smarty->assign("PublishDate",$post_date);
$smarty->assign("ModifyDate",$post_modified);
//$smarty->display("page.tpl");
$out = $smarty->fetch("page.tpl");
$filename = "/usr/local/src/document/articles/{$id}.html";
if ($pageid==1050){
$filename = "/usr/local/src/document/wiki.html";
}
$handle = fopen($filename, "w");
fwrite($handle,$out);
fclose($handle);
echo $filename."\n";
[/code]