smarty能创建 php页面,smarty 生成静态html页面

生成静态页面,用php生成会比smarty生成要快,但是如果你用smarty模板做的页面,现在要生成html的话,就可以看看这篇smarty 生成静态html页面教程物。

$tpl = new Smarty();

$tpl->template_dir = dirname(__FILE__);

$tpl->compile_dir = 'phprm.com';

$tpl->compile_check = false; //$cfg['debug'];

$tpl->debugging = 0;

$tpl->caching = 0;

$tpl->cache_lifetime = 3600;

$tpl->left_delimiter = '';

//初始化smarty模板

$file = date("Y-m-d") . ".html";

$tempFile = 'template.tpl';

//解析模板文件

$tpl->assign('title', 'php smarty 生成静态html页面');

$tpl->assign('content', '这是文章内容');

$content = $tpl->fetch($tempFile, null, null, false);

//关键一步就是把 $content生成html 文件就行了,下面来看

$dir = dirname($file);

//目录不存在就创建

if (!file_exists($dir)) {

creatDir($dir);

}

$handle = fopen($file, "w+"); //创建文件

if (!is_writable($file_name)) { //判断写权限

echo '没有写权限';

}

if (!fwrite($handle, $content)) {

echo '文件不可写';

}

fclose($handle); //关闭指针

echo '生成静态页面成功'; //返回文件名

function creatDir($dir) {

if (!is_dir($dir)) {

if (!creatDir(dirname($dir))) {

return false;

}

if (!mkdir($dir, 0777)) {

return false;

}

}

return true;

}

//tmplate.tpl 代码

转载随意^^请带上本文地址!


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部