每次都搞了头大,搞清楚方法。一切都清晰。
思路:我们先输出模版文件在哪个文件夹。然后再去修改相应模版。
1. 写一个配置文件smarty.ini.php:
<?PHP
//引用类文件?
require 'smarty/Smarty.class.php';
$smarty = new Smarty;
//$smarty=new Smarty;
//设置各个目录的路径,这里是安装的重点
$smarty->template_dir="templates/templates";
$smarty->compile_dir="templates/templates_c";
$smarty->config_dir="templates/config";
$smarty->cache_dir="templates/cache";
//smarty模板有高速缓存的功能,如果这里是true的话即打开caching,但是会造成网页不立即更新的问题,当然也可以通过其他的办法解决
$smarty->caching=false;
?>
2. 在使用模板的index.php文件中:
<?php
include "smarty.ini.php";
$title="Smarty-Learn-Test";
$content="Smarty_content哈哈";
$auth="MarcoFly";
$website="www.MarcoFly.com";
$smarty->assign("title",$title);
$smarty->assign("content",$content);
$smarty->assign("auth",$auth);
$smarty->assign("website",$website);
$smarty->display("index.html");
?>
相应的index.html文件:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>{$title}</title>
</head>
<body>
<p>内容:{$content}</p>
<p>作者:{$auth}</p>
<p>网址:{$website}</p>
</body>
</html>
Copyright © 2004-2024 Ynicp.com 版权所有 法律顾问:建纬(昆明)律师事务所 昆明市网翼通科技有限公司 滇ICP备08002592号-4