Smarty 没有输出,请教,散分 apache有权限写'/var/www/html/Smarty/templates_c/‘ 这个目录吗?你的test.htm放在那个目录里啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 保证你的templates_c和cache两个目录可写。把test.htm放到template里面。 确保那些目录都存在templates_c和cache必需可写 给你个sampleindex.php<? include_once('smarty/Smarty.class.php'); $broadcast = '你好!!'; //创建模板 $smarty = new Smarty; $smarty->template_dir = './'; $smarty->compile_dir = './templates_c/'; $smarty->config_dir = './configs/'; $smarty->cache_dir = './cache/'; $smarty->left_delimiter = '{<'; $smarty->right_delimiter = '>}'; $smarty->assign('broadcast',$broadcast); //显示模板 $smarty->display('index.htm');?>index.htm<HTML>smarty显示的信息:{<broadcast>}</HTML> main.php文件如下<?phprequire ('./comm/smarty.class.php');define ('_SITE_ROOT','E:/smarty');$tp1=new smarty();$tp1->template_dir=_SITE_ROOT.'/templates/';$tp1->template_c=_SITE_ROOT.'/templates_c/';$tp1->config_dir=_SITE_ROOT.'/configs/';$tp1->cache_dir=_SITE_ROOT.'/cache/';$tp1->left_delimiter='{';$tp1->right_delimiter='}';?>test.php文件如下<?phprequire ('main.php');global $tp1;$tp1->assign('title','测试用的网页');$tp1->assign('content','测试用的网页内容');$tp1->display('test1.html');?>test1.html如下显示<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE> New Document </TITLE><META NAME="Generator" CONTENT="EditPlus"><META NAME="Author" CONTENT=""><META NAME="Keywords" CONTENT=""><META NAME="Description" CONTENT=""><meta http-equiv="Content-Type" content="text/html; charset=gb2312"></HEAD><BODY>{$title}<br/>{$content}</BODY></HTML> 有错误的话smarty要有错误信息的,贴出来看看呀。 结贴:因为$smarty->template_dir='/var/www/html/Smarty/templates/',所以test.htm应该放到templates目录里面。多谢各位! 求正则表达式:只保留字符串中的汉字和字母 求助怎么带入变量呢啊? 要求PHP实现页面局部刷新 关于php中正则式的问题 祝大家平安夜有苹果吃~~~~~~ 急~!!关于文字编码的问题 谢谢了UTF-8 TO GB2312 急!表单直接提交到邮箱的方法,php空间,在线等待 请问如何将MYSQL数据库表中的数据以表格形式显示出来,且偶数行背景颜色加深? 关于if...else...又一问 PHP进阶书籍求推荐 如何让服务器支持中文名文件,本论坛搜不到的问题~ 如何在本地网页中隐形实现另一个网站的身份验证来登录那个网站
templates_c和cache必需可写
index.php
<?
include_once('smarty/Smarty.class.php');
$broadcast = '你好!!';
//创建模板
$smarty = new Smarty;
$smarty->template_dir = './';
$smarty->compile_dir = './templates_c/';
$smarty->config_dir = './configs/';
$smarty->cache_dir = './cache/';
$smarty->left_delimiter = '{<';
$smarty->right_delimiter = '>}'; $smarty->assign('broadcast',$broadcast);
//显示模板
$smarty->display('index.htm');
?>index.htm
<HTML>
smarty显示的信息:{<broadcast>}
</HTML>
<?php
require ('./comm/smarty.class.php');
define ('_SITE_ROOT','E:/smarty');
$tp1=new smarty();
$tp1->template_dir=_SITE_ROOT.'/templates/';
$tp1->template_c=_SITE_ROOT.'/templates_c/';
$tp1->config_dir=_SITE_ROOT.'/configs/';
$tp1->cache_dir=_SITE_ROOT.'/cache/';
$tp1->left_delimiter='{';
$tp1->right_delimiter='}';
?>test.php文件如下
<?php
require ('main.php');
global $tp1;
$tp1->assign('title','测试用的网页');
$tp1->assign('content','测试用的网页内容');
$tp1->display('test1.html');
?>
test1.html如下显示
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</HEAD>
<BODY>
{$title}
<br/>
{$content}
</BODY>
</HTML>