1.解压:Smarty-2.6.20.tar.gz
2.把Smarty-2.6.20/libs下的全部Copy到php目录下的一个包中(我取名smarty/classes)
3.在smarty下建立test.php,
4.//-------------------------------------------------------------------------
<?php
include("./aa/Smarty.class.php"); //包含smarty类文件
$smarty = new smarty(); //建立smarty实例对象$smarty
$smarty -> template_dir = "./templates"; //模板存放目录
$smarty -> compile_dir = "./cc"; //编译目录
$smarty->config_dir = "./config";
$smarty->cache_dir = "./cache";
//----------------------------------------------------
//左右边界符,默认为{},但实际应用当中容易与JavaScript
//相冲突,所以建议设成<{}>;或其它。
//----------------------------------------------------
$smarty -> left_delimiter = "{{"; //左定界符
$smarty -> right_delimiter = "}}"; //右定界符
$smarty -> assign('name', '小林'); //进行模板变量替换
$smarty -> assign('nn', '奥运会'); //进行模板变量替换
//编译并显示位于./templates下的index.tpl模板
$smarty->display('test.txt');
?>;
//------------------------------------------------------------
5.在smarty/templates下建立模板文件test.tpl
<html>
<head>
</head>
<body>
<hr/>
<table align="center">
<h1>
{{$name}}
</h1>
</table>
</body>
</html>
6.建立smarty/cc作为编译文件路径
7.访问http://localhost/dianzi/smarty/test.php

被折叠的 条评论
为什么被折叠?



