Samrty模板引擎在php项目中的使用方法

(1)在smarty官网http://www.smarty.net/download上去下载smarty;

(2)打开文件夹,demo文件夹是smarty使用的一些案例,libs文件夹下是smarty的源文件;

(3)将libs文件夹复制到项目文件夹下面,将其名字改为Smarty以免跟其他文件夹出现分歧;


(4)在同级目录创建一个文件夹test,新建文件config.php,配置如下:

<?php
require_once '../smarty/Smarty.class.php';
$smarty=new Smarty();
/* Smarty的五配置两方法 */
//五配置
$smarty->left_delimiter='{';//左定界符
$smarty->right_delimiter='}';//右定界符
$smarty->template_dir='tpl';//html模板的地址
$smarty->compile_dir='template_c';//模板编译生成的文件
$smarty->cache_dir='cache';//缓存
//两方法
$smarty->caching=true;//开启缓存
$smarty->cache_lifetime=120;//缓存时间

配置完成后test文件夹的内容如图:


(5)在每个要使用模板引擎的文件中导入config.php文件就可以使用模板了

<?php
header("content-type:text/html;charset=utf-8");
require 'config.php';
$smarty->assign('str','Hello,My name is xioaying。How are you?');
$smarty->display('content.tpl');



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值