1. 下载Smarty最新版: http://www.smarty.net/download
2. libs目录下的文件都是Smarty需要的库文件,只要将该文件夹拷贝到要使用Smarty技术的网站根目录就能够使用Smarty了。为了不和已有的文件夹重名,可以修改文件夹的名字为Smarty。
3.在网站根目录下建立如下的目录结构 来测试Smarty的使用。
----Smarty-learn
--------------------smarty(smarty的库文件)
--------------------templates---cache
------------------------------------config
------------------------------------templates--------index.html(模版文件)
------------------------------------templates_c
--------------------index.php
index.html 的内容:
<html>
<title><head>test smarty</head></title>
<body>
{$color}
</body>
</html>
index.php的内容:
<?PHP
//引用类文件?
require 'smarty/Smarty.class.php';
$smarty = new Smarty;
//设置各个目录的路径,这里是安装的重点
$smarty->template_dir="templates/templates";
$smarty->compile_di

本文介绍了Smarty模板引擎的安装步骤,包括下载最新版本、设置目录结构以及配置 Smarty 的 template_dir、compile_dir、config_dir 和 cache_dir。通过创建简单的 index.html 模板和 index.php 控制器文件,展示了如何在 PHP 中使用 Smarty 进行变量赋值和显示。当在浏览器中运行并看到预期的 'green' 字样时,标志着 Smarty 安装成功。
最低0.47元/天 解锁文章
3534

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



