list.php<?
require_once 'smarty_config.php';
require_once 'conn.php';

//读取数据
$sql="select * from news order by id desc";
$row = mysql_query($sql);
while($re1r=mysql_fetch_array($row)){
$array[]=$re1r;
}
print_r($array);
$smarty->assign("titlelist",$array);
$smarty->display("list.tpl");


?>
list.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新闻列表</title>
</head><body>
<table width="100%" border="0">
  <tr>
    <td colspan="4">新闻中心</td>
   
  </tr>
  
{section name=titlelist loop=$titlelist}
  <tr>
    <td></td>
    <td>{$titlelist[titlelist].news_title}</td>
<td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
{/section}
  </table></body>
</html>
打死不显示,错误提示如下:
Fatal error: Smarty error: [in list.tpl line 15]: syntax error: unrecognized tag: (Smarty_Compiler.class.php, line 446) in E:\phpweb\htmlsmarty\smarty\Smarty.class.php on line 1095请问高手我那里写错了,找了半天没找到错误

解决方案 »

  1.   

    $smarty->display("list.tpl");
    ?>
    list.html
      

  2.   

    不是这个问题。我在本地的模板文件名称是list.tpl
      

  3.   

    你那错误提示是标签识别不了。有可能是你smarty设置了左右标签而不是默认的{}。
      

  4.   


    //引用类文件
    require_once 'Smarty/Smarty.class.php';
    //实例化smarty
    $smarty = new smarty;
    //引入smarty目录变量
    require_once 'Smarty/Config_File.class.php';
    //smarty 配置文件
    $smarty->cache = false;   //不开启
    $smarty->templates= './templates' ;   //模板文件
    $smarty->compile_dir = './templates_c'; //编译文件夹
    $smarty->cache_dir = './cache';   //缓存文件夹


    $smarty->right_delimiter="{";
    $smarty->left_delimiter="}";
      

  5.   


    $smarty->display("list.tpl");改为:$smarty->display("list.html");