什么是smarty?
Smarty是一个使用php写出来的php模板引擎
Smarty优点:
(1)速度快:相对其它的模板引擎
(2)编译型:采用smarty编写的程序在运行时要编译成一个模板技术的php文件
(3)缓存技术:它可以将用户最终看到的HTML文件缓存成一个静态的HTML页
(4)插件技术:smarty可以自定义插件
不适合smarty使用的地方:
需要实时更新的内容,小项目
Smarty的配置:
include_once("libs/Smarty.class.php");//包含smarty类文件
$smarty=
newSmarty();
//建立smarty实例对象$smarty
$smarty->caching=false;//是否使用缓存,项目在调试期间,不建议启用缓存
$smarty->template_dir=
"./templates";//设置模板目录
$smarty->compile_dir=
"./templates_c";//设置编译目录
$smarty->cache_dir=
"./smarty_cache";//缓存文件夹--
//左右边界符,默认为{},但实际应用当中容易与JavaScript相冲突
//因此建议替换为<{}>
$smarty->left_delimiter=
"<{";
$smarty->right_delimiter=
"}>";
Smarty:
Libs
dome
$smarty->assign();
$smarty->display();
<{$smarty.now}>:相当于time(时间戳)
模板文件名不重要