php模板smarty 例子,php Smarty 模板简单实例

一、建立一个php Project,文件目录如下图

0818b9ca8b590ca3270a3433284dd417.png

二、文件说明

1、libs:是Smarty类库

2、tpl/cache_dir:存放缓存模板

3、tpl/compile_dir:存放编译后模板文件

4、tpl/config_dir:存放特殊配置文件

5、tpl/template_dir:存放模板文件

6、smarty.php文件里 new 出了一个 Smarty类对象,并设定各对象的属性值,如下代码

require 'libs/Smarty.class.php';//加载Smarty.class.php文件

define('SITE_ROOT','./tpl/');//定义一个常量

$tpl = new Smarty();

$tpl->template_dir = SITE_ROOT . 'template_dir';//存模板文件

$tpl->compile_dir = SITE_ROOT . 'compile_dir';//存编译过的模板文件

$tpl->config_dir = SITE_ROOT . 'config_dir';//存特殊配置文件

$tpl->cache_dir = SITE_ROOT . 'cache_dir';//存Smarty缓存文件

$tpl->caching = 1;//启用缓存

$tpl->cache_lifetime = 60*60*24;//缓存时间1天

$tpl->left_delimiter = '

$tpl->right_delimiter = '}>';//右结束符

7、index.php文件 首页 代码如下

require 'smarty.php';

$tpl->assign('title','title测试');

$tpl->assign('content','content测试');

$tpl->display('template.html');

8、tpl/template_dir/template.html 这是一个模板文件 代码如下

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值