php的smarty模板,PHP Smarty模板的安装

最近开发中用到了PHP中smarty模板。。作为一个长久以来的前端,开始学习PHP模板。。下面将安装教程分享给大家。。

1. 下载Smarty最新版: http://www.smarty.NET/download

2. libs目录下的文件都是Smarty需要的库文件,只要将该文件夹拷贝到要使用Smarty技术的网站根目录就能够使用Smarty了。为了不和已有的文件夹重名,可以修改文件夹的名字为Smarty。

3.在网站根目录下建立如下的目录结构 来测试Smarty的使用。

----Smarty-learn

--------------------smarty(smarty的库文件)

--------------------templates---cache

------------------------------------config

------------------------------------templates--------index.html(模版文件)

------------------------------------templates_c

--------------------index.PHP

index.html 的内容:

test smarty

{$color}

index.php的内容:

//引用类文件?

require 'smarty/Smarty.class.php';

$smarty = new Smarty;

//设置各个目录的路径,这里是安装的重点

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

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

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

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

//smarty模板有高速缓存的功能,如果这里是true的话即打开caching,但是会造成网页不立即更新的问题,当然也可以通过其他的办法解决

$smarty->caching=false;

$hello = "hello smarty!";

$smarty->assign('hello',$hello);

$bgcolor = "green";

$smarty->assign('color',$bgcolor);

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

?>

在浏览器输入http://localhost/Smarty-learn/,如果出现green,说明测试成功,Smarty没有任何问题,已经可以使用了。

这样的目录结构并不是必须的,只要在使用Smarty的时候配置好这几个目录的路径,任何目录结构都是可以的。但是建议这样使用,层次清楚,不影响网站其他部分。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值