Smarty安装:
下载并解压Smarty2.6.5,将其smarty文件夹(注意含有 3 个 class.php + 1 个 debug.tpl + 1 个 plugin + 1 个 core )复制到主程序文件夹下,然后在同一位置建configs,includes,modules,templates,templates_c五个文件夹.Linux下,将 templates_c 的权限变更为 777 .
Smarty测试。
index.tpl放到templates文件夹下,
内容为:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><{$title}></title>
</head>
<body>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><{$title}></title>
</head>
<body>
<{$content}>
</body>
</html>
</body>
</html>
index.php放到主程序文件夹下,
如下:
<?php
include("./class/Smarty.class.php"); //包含smarty类文件
include("./class/Smarty.class.php"); //包含smarty类文件
$smarty = new Smarty(); //建立smarty实例对象$smarty
$smarty->template_dir = './templates/';
$smarty->compile_dir = './templates_c/';
$smarty->config_dir = './configs/';
$smarty->cache_dir = './cache/';
$smarty->caching = false;
$smarty->template_dir = './templates/';
$smarty->compile_dir = './templates_c/';
$smarty->config_dir = './configs/';
$smarty->cache_dir = './cache/';
$smarty->caching = false;
$smarty->left_delimiter = "<{";
$smarty->right_delimiter = "}>";
$smarty->assign("title", "垃圾"); //进行模板变量替换
$smarty->assign("content","测试用的网页内容00");
//编译并显示位于./templates下的index.tpl模板
$smarty->display("index.tpl"); //index.tpl
?>
$smarty->assign("content","测试用的网页内容00");
//编译并显示位于./templates下的index.tpl模板
$smarty->display("index.tpl"); //index.tpl
?>
在ie输入 http://localhost/index.php测试