(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文件夹的内容如图:
<?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');