require_once('./Library/Smarty/Smarty.class.php') ;//引入文件类
$swl = new Smarty(); //实例化
$swl->template_dir="template"; //指定模版存放目录
$swl->compile_dir="Cache/php"; //指定编译文件存放目录
$swl->config_dir="Cache/conf"; //指定配置文件存放目录
$swl->cache_dir="Cache"; //指定缓存存放目录
$swl->caching=false; //开启缓存(true表示启用缓存)
$swl->left_delimiter="{:"; //指定左标签
$swl->right_delimiter=":}"; //指定右标签
下面的index.php和one.php的变量解析都OK,而view.php出错。
index.php
<?php
require_once 'Library/header.php';
//require_once('/include/footer.php');
$name="OK11";
$swl->assign('name',$name);
$swl->display("index.html");
?>
index.html
<html>
<title>{:$name:}</title>
<body>
<h1>{:$name:}</h1>
<a href="view.php?act=kakakak">VIEW</a>
<br>
<a href="one.php?act=kakakak">VIEW</a>
</body>
</html>one.php
<?php
require_once 'Library/header.php';
//require_once('/include/footer.php');
$name=$_GET['act'];
$pa="23";
$swl->assign('napme',$name);$swl->assign('pa',$pa);
$swl->display("read.html");
?>
read.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="./public/haha.css">
</head>
<body>
<h1>{:$napme:}</h1>
adfasdfadf{:$napme:}adf{:$pa:}
</body>
</html>view.php
<?php
require_once 'Library/header.php';
//require_once('/include/footer.php');
$nahme="OK1wqwtr1";
$swl->assign('nameaa',$nahme);
$swl->display("view.html");
?>
view.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>哈哈哈哈</title>
<link rel="stylesheet" type="text/css" href="./public/haha.css">
</head>
<body>
fd{:nameaa:}sf
</body>
</html>index.php和one.php都可以成功解析模板变量显示正常,可是那个view.php总是出现下面的错误,是什么原因,view.php错误如下:?Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "G:/WwwRoot/one/template\view.html" on line 9 "fd{:nameaa:}sf" unknown tag "nameaa"' in G:\WwwRoot\one\Library\smarty\sysplugins\smarty_internal_templatecompilerba
最佳答案