Smarty 是有php模板引擎。目的就是使php程序员与美工之间工作的分离。
类似的模板选择还有phplib,
优点:
同类模板中速度最快的一个,
编译型:编译成非模板文件,即php与html混合的方式,下次访问,直接访问编译过的文件,不再重新编译,提高访问速度。
缓存技术:启用配置为true,在cachetime时间内,将web请求直接转换到一个静态的html文件中来,提高访问速度,但可能更新不及时。
插件技术:可以自定义插件,较强的扩展性
模板中可以使用判断语句,可以根据需求选择具体得格式。
缺点:更新不及时,由于其编译,缓存的特点,在提高速度的同时降低时效性。
不适合小项目的开发,工作分离要求低,编译过程反而会降低效率。
Smarty使用:
Libs 核心库,templates包里面含有cache,templates,templates_c,configs
一个简单的demo:
首先建立一个模板,然后配置路径
$smarty->template_dir ="smarty/templates/templates";
$smarty->compile_dir ="smarty/templates/templates_c";
$smarty->config_dir = "smarty/templates/config";
$smarty->cache_dir ="smarty/templates/cache";
$smarty->caching = false;
$hello = "Hello World!";//赋值
$smarty->assign("hello",$hello);// 引用模板文件
$smarty->display('index.tpl');
开始的时候cache,templates_c为空,运行之后生成相应的文件,保证有读写权限。
smarty 初探
最新推荐文章于 2024-07-17 16:42:25 发布