php中smarty末班引擎,PHP使用smarty模板引擎

Smarty是一个使用PHP写出来的模板引擎,目的是分离php代码和html代码。是一个编译型模板引擎。

安装

(1)下载Smarty,

(2)在web服务器文档根目录新建一个smarty/文件夹,

(3)把解压Smarty后lib文件夹里的文件拷到smarty/下,

(4)在smarty/下新建4个文件夹template/自已的模板文件,templates_c/编译时生成的文件,cache/缓存的文件,configs/配置文件。

(5)编码指定(4)中的4个文件夹路径。在文档根目录下新建文件smart.php

require 'smarty/libs/Smarty.class.php';

$smarty = new Smarty();//设置各个目录的路径,这里是安装的重点

$smarty->template_dir ="smarty/libs/templates/templates";

$smarty->compile_dir ="smarty/libs/templates/templates_c";

$smarty->config_dir = "smarty/libs/templates/config";

$smarty->cache_dir ="smarty/libs/templates/cache";

?>

使用

(1)在文档根目录/smarty/template/下新建模板文件index.tpl

smarty demo

It's as easy as {$test}.

(2)在文档根目录/新建php文件index.php

require_once("smarty.php");

$smarty->assign('test', 123);

$smarty->display('index.tpl');

?>(3)通过浏览器来访问index.php,http://localhost/index.php就会显示:

It's sa easy as 123.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值