问题:Smarty3.0 直接输出变量本身,不解析变量!
index.php 代码:
<?php
include('../config.inc.php');
define('SMARTY_PATH',ROOT_DIR.'Smarty/');
require(SMARTY_PATH.'Smarty.class.php');
$smarty=new Smarty;
$smarty->template_dir=SMARTY_PATH.'template/';
$smarty->compile_dir=SMARTY_PATH.'template_c/';
$smarty->config_dir=SMARTY_PATH.'configs/';
$smarty->cache_dir=SMARTY_PATH.'cache/';
$smarty->left_delimiter='{%';
$smarty->right_delimiter='%}';
$smarty->assign('title','第一个SMARTY程序!');
$smarty->assign('content','HELLO,WELCOME TO \'SMARTY\' WORLD!!');
$smarty->display('index.tpl');
?>
index.tpl模板页代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{% $title %}</title>
</head>
<body>
{% $content %}
</body>
</html>
解决方法:
方法1:去掉模板页变量左右边的空格,如:{%$title%} ,因为Smarty3.0相对2.0,默认是不支持变量间出现空格的,以更好的与JS兼容;
方法2: 在Smarty定界符的配置项中添加空格,使Smarty变量左右能出现空格,如:
修改前:$smarty->left_delimiter='{%';
修改后:$smarty->left_delimiter='{% '; (%后有一空格)
0条评论( 网友:0 条,站长:0 条 ) 网友评论{有您的评论更精彩....}