关于smarty作网站的问题求解谢谢

c_h_l 2008-01-31 10:24:04
小弟刚学PHP不久,发现smarty是个不错的东西,所以现在正试用smarty制作一个网站练练手。

一共五个文件夹,分别是:cache libs require templates 和 templates_c

现在我从网站上下载了一个别人的模板,我用photoshop自己切后又导出WEB格式就成了images文件夹和index.html文件,我把这两个东西放在templates文件中以作为网站的主页网页模板。

在标注几个smarty变量后用smarty输出这个index.html文件的,发现并没有把我切的那些一个一个的小图片显示出来全是一些未显示的小叉。当我把index.html打开后把每个<img src="images/index_01.png" width="204" height="41" alt="">改成<img src="templates/images/index_01.png" width="204" height="41" alt="">后就显示出来了,但是有好多的小图片一个一个改麻烦,请问有别的简便的方法吗?

求解谢谢大哥们给予帮助。
...全文
153 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
c_h_l 2008-07-23
  • 打赏
  • 举报
回复
谢谢大家了。。。。
infoseek 2008-04-07
  • 打赏
  • 举报
回复
讲得很详细了,最近也在尝试了解smarty

我觉得现在只需要了解应用层面上的东西就可以了,至于smarty后面的原理就不需要再深究了
nxdawukous 2008-02-10
  • 打赏
  • 举报
回复
1.在你的“localhoat”目录下建立新的目录learn/,在learn下建立目录
smarty/,将刚才解压出来的目录的libs/拷贝到smarty/里,再在smarty/
里新建templates目录,templates里新建cache/,templates/,templates_c/,
config/,如下图所示

--learn
--smarty
--libs
--internals
--plugins
--templates
--cache
--configs
--templates
--templates_c

2.新建一个模板文件:index.tpl 将此文件放在learn/smarty/templates/templates
目录下,代码如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML4.01
Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type"
content="text/html";charset="ge2312">
<title>Smarty</title>
</head>
<body>
{$hello}
</body>
</html>

新建index.php 将此文件放在learn/下

<?php
//引用类文件
require("smarty/libs/Smarty.class.php");
$smarty=new Smarty;

//设置各个目录的路径,这是安装的重点
$smarty->template_dir="smarty/templates/templates";
$smarty->compile_dir="smarty/templates/templates_c";
$smarty->config_dir="smarty/templates/config";
$smarty->cache_dir="smarty/templates/cache";

//smarty模板具有高速缓存的功能,如果这里是true的话即打开caching,
//但是会造成网页不会立即更新的问题,当然也可以通过其它的办法解决
$smarty->caching=false;

$hello="hello,world";
$smarty->assign("hello",$hello);//对类模板中的变量赋值
$smarty->display("index.tpl");//加载类模板
?>

注:Smarty.class.php文件定义了类$Smarty及几个常量。

3.执行index.php 就能在页面上输出"hello,world"

先声明:我是抄别人的,不过我已经把一些东西改动了,你照上面的做 一定可以配置好,然后就明白SMARTY的原理了。
张吉Jerry 2008-02-07
  • 打赏
  • 举报
回复
我比较喜欢的做法:
$smarty->template_dir="./";
跟templates目录说byebye~
bieye615 2008-02-02
  • 打赏
  • 举报
回复
文件夹分别是:cache libs require templates 和 templates_c
在同级下再建images放图片,不要放在templates里
而模板文件可以不用改为.tpl
不过,建意改一下好

ichigoxi 2008-02-02
  • 打赏
  • 举报
回复
对,就是这个意思,既然是模板语言,肯定模板和php文件是分开的。这样代码上比较清晰。
基本用法如下:
//定义网站根目录
define("SITE_ROOT","/web/vms/");
define("WEB_ROOT","/vms");
define("IMAGE_ROOT","/vms/images");

//定义smarty模板类相关配置
include SITE_ROOT."libs/Smarty.class.php";

//定义数据库相关配置
$db_host = "localhost";
$db_user = "root";
$db_password = "";
$db_name = "cvs";

$tpl = new Smarty();
$tpl->caching = false;
$tpl->template_dir = SITE_ROOT . "templates/";
$tpl->compile_dir = SITE_ROOT . "templates_c/";
$tpl->config_dir = SITE_ROOT . "configs/";
$tpl->cache_dir = SITE_ROOT . "cache/";
$tpl->left_delimiter = '<{';
$tpl->right_delimiter = '}>';

$tpl->assign("web_root",WEB_ROOT);
$tpl->assign("image_root",IMAGE_ROOT);
//定义页面title
$tpl->assign("page_title","网站TITLE");

你的PHP页再include这个页,调用tpl就OK了~祝你早日搞定
c_h_l 2008-02-01
  • 打赏
  • 举报
回复
不是吧,肯定有更好的方法。继续求解。
c_h_l 2008-02-01
  • 打赏
  • 举报
回复
感谢大家的帮助。

可能我还不懂smarty的原理吧|||

ichigoxi你好,你的意思是不是我要从新建一个专门放.HTML网页页面模板的文件夹,然后templates里全是.tpl文件?每个.tpl文件都是引用.html文件?
genshing你好,我会试试你的方法的,呵呵谢谢。
genshing 2008-02-01
  • 打赏
  • 举报
回复
要不然就把图片的文件夹剪切到网站根目录。
ichigoxi 2008-02-01
  • 打赏
  • 举报
回复
SMARTY不是这么用的...templates文件夹是用来放模板的xxx.tpl,因为这是一种模板语言啊...
而你说的那些图片链接都是基于调用模板的那个xxx.php页面的,所以链接位置根本不用templates/images/index_01.png这样。如果PHP页面与IMAGE文件夹一个目录的话,直接写images/index_01.png就可以了。建议LZ去搜下SMARTY的介绍文章,网上有不少的。
genshing 2008-02-01
  • 打赏
  • 举报
回复
批量替换。
cc8476 2008-01-31
  • 打赏
  • 举报
回复
查找,替换
c_h_l 2008-01-31
  • 打赏
  • 举报
回复
继续求解

21,890

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧