一、下载smarty压缩包
二、解压smarty压缩包,把里面的libs文件夹复制到网站的根目录下面,然后建立两个文件夹分别是templates 和 templates_c,
templates 文件夹是存放模版文件的,
templates_c 文件夹是存放编译文件的
三、输出简单的hello,world
建立模版文件hello.tpl放到templates文件夹下面 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<{$hello}>
</body>
</html>
建立一个php文件放到根目录下 代码如下:
<?php
include_once("libs/Smarty.class.php"); // 包含smarty类文件
$smarty=new Smarty(); // 建立smarty实例对象$smarty
$smarty->caching=false; // 是否使用缓存
$smarty->template_dir="./templates/"; // 设置模版目录
$smarty->compile_dir="./templates_c/"; //设置编译目录
$smarty->cache_dir="./smarty_cache/"; // 缓存文件夹
// 设置作用边界符 默认是{ } 一般用<{ }>
$smarty->left_delimiter="<{";
$smarty->right_delimiter="}>";
// 从php分配变量给模版文件
$smarty->assign("hello","hello,world");
$smarty->display("hello.tpl");
?>
这样就可以输出hello,world了 这也是smarty的简单配置,关于smarty的更多内容敬请关注。。。。