smarty模板可以在本站下载http://www.phpfans.net/download.php?page=2

 

1.1Smarty环境要求
Smarty要求web服务器运行php4.0.6或以上版本。
1.2Smarty基本安装
Smarty库文件放到/libs/目录中 ,这些文件不需要编译,被所有的应用程序共享。
必需要有的库文件
Smarty.class.php,Smarty_Compiler.class.php,Config_File.class.php,Debug.tpl

 

Smarty使用一个叫做SMARTY_DIR的php常量作为它的系统库目录。基本上,如果你的应用程序可以找到Smarty.class.php文件,则你不需要设置SMARTY_DIR,Smarty将自己运作

 

运行上面的脚本,如果得到了一个错误:Smarty.class.php文件找不到,则你必须按下面的方法做:
方法一:手动定义SMARTY_DIR常量
[复制到剪切板]
CODE:
<?php
    define(“SMARTY_DIR”,”库文件的目录”);
    require_once(SMARTY_DIR.'Smarty.class.php');
    $smarty=new Smarty();
?>
方法二:提供库文件的绝对目录
[复制到剪切板]
CODE:
<?php
    Require_once(“…………/libs/Smarty-v.e.r/libs/Smarty.class.php”);
    $smarty=new Smarty();
?>
方法三:添加库目录到PHP inlcude_path
[复制到剪切板]
CODE:
<?php
    require_once(“Smarty.class.php”);
    $smarty=new Smarty();
?>
总之你必须通过一种方法让你的程序找到Smarty.class.php

 

Smarty要求有四个目录,它们的默认名分别为'templates/','templates_c/','configs/','cache/'
它们都可以通过修改Smarty类的$template_dir,$compile_dir,$config_dir,$cache_dir属性重新定义。

 

语法

 

{* Smarty *}
Hello {$name},welcome to Smarty!
{* Smarty *}是一个模板注释。这不是必需的,但是这可以很好的锻炼你在模板文件里加入注释的习惯