日期:2014-05-17  浏览次数:20465 次

Smarty模版,tpl显示问题
刚开始学习Smarty模版,其它的配置什么都能成功,但是在写第一个试验程序的无法正常显示
  index.php中的内容::
  <?php
  /*载入配置文件*/ 可以确定config文件配置正确。。。。。
include '../config.php';
/*声明数组*/
$arr = array('computerbook','name'=>'PHP进阶阶段','unit_price'=>array('price'=>'¥65.00','unit'=>'本'));
/*将标题和数组传给模版*/
$smarty -> assign('title','使用Smarty读取数组');
$smarty -> assign('arr',$arr);
/*要显示的模版页*/
$smarty ->display('02/index.tpl');
  ?>
  index,tpl模版文件中:
  <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title> {% $title %} </title>
  <meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
 </head>

 <body>
  购书信息:<p>
{% *使用索引取得数组第一个元素值* %}
图书类别: {% $arr[0] %}<br/>
{% *使用键值取得第二个数组元素值* %}
图书名称: {% $arr.name %}<br/>
{% *使用键值取得二维数组的元素值* %}
图书单价: {% $arr.unit_price.price %}/{% $arr.unit_price.unit %}
   
 </body>
 </html>
  在浏览器中访问的时候却出现直接在网页中输出了:
  购书信息:

{% *使用索引取得数组第一个元素值* %} 图书类别: {% $arr[0] %}
{% *使用键值取得第二个数组元素值* %} 图书名称: {% $arr.name %}
{% *使用键值取得二维数组的元素值* %} 图书单价: {% $arr.unit_price.price %}/{% $arr.unit_price.unit %} 

望高手解答
 

------解决方案--------------------
你是通过什么地址访问的?
------解决方案--------------------
你直接访问模板页了吧
------解决方案--------------------
你是从index.php页面开始访问吗?$smarty ->display('02/index.tpl');
显示的模板文件