smarty的使用

之前有个准备工作,1、引入smarty类库 2、在同级目录新建 temp和comp文件夹,分别存放模板和解析后模板,还要新建一个conf的配置文件

1、引入smarty

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

2、实例化
$smarty=new Smarty();

3、配置必要的选项

$smarty->template_dir='./temp';//模板路径
$smarty->compile_dir='./comp';//解析后保持路径
$smarty->config_dir = './conf/';//配置文件路径

4、赋值

$smarty->assign('content','题俺贴吧多');
$smarty->assign(array('name'=>'huohaifeng','age'=>18));
$huo=array('sex'=>'nan','name'=>'huo','age'=>'24');
$smarty->assign('huo',$huo);

define('time', '8点半');

5、引入模板

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

原文地址:https://www.cnblogs.com/hhfhmf/p/4807275.html