====== Smarty 简单例子 ======
下面的例子是基于Smarty 2.6版本的,可以不适用与Smarty 3。
===== Smarty 目录结构 =====
创建以下三个目录结构:
smarty/
smarty_run/
templates/
* smarty: smarty库文件
* smarty_run: smarty临时文件
* templates: .tpl模板文件
===== php脚本设置 =====
require("smarty/libs/Smarty.class.php");
$smarty = new Smarty;
$smarty->config_dir="smarty/libs/Config_File.class.php";
$smarty->caching=false;
$smarty->cache_dir="smarty_run/cache/";
$smarty->template_dir="templates";
$smarty->compile_dir="smarty_run/templates_c/";
$smarty->left_delimiter = "{{";
$smarty->right_delimiter = "}}";
// ...
// ...
// pass variables to smarty
$url = "http://www.pythonclub.org/";
$smarty->assign('title', $title);
$smarty->assign('url', $url);
$smarty->assign('post', $post);
$smarty->assign('id', $id);
$smarty->display('post.tpl');
===== tpl模板文件 =====