smarty升级到3.x后的空格问题

前几天处理一个PHP升级到5.3后的一些网站运行问题,发现有好多的报这个错误.

Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "./templates/1.html" on line 1 "&lt;{if $var }&gt; " - Unexpected " }>", expected one of: "|" , "}>" , "*" , "/" , "%" , "+" , "-" , ""&"" , ISIN , ISDIVBY , ISNOTDIVBY , ISEVEN , ISNOTEVEN , ISEVENBY , ISNOTEVENBY , ISODD , ISNOTODD , ISODDBY , ISNOTODDBY , "==" , "!=" , "(>,gt)" , "(<,lt)" , "(>=,ge)" , "(<=,le)" , "===" , "!==" , "(%,mod)" , "(&&,and)" , "(||,or)" , "xor"' in E:wwwSmarty-3.0rc4libssyspluginssmarty_internal_templatecompilerbase.php:404 Stack trace: #0 E:wwwSmarty-3.0rc4libssyspluginssmarty_internal_templateparser.php(2666): Smarty_Internal_TemplateCompilerBase->trigger_template_error() #1 E:wwwSmarty-3.0rc4libssyspluginssmarty_internal_templateparser.php(2731): Smarty_Internal_Templateparser->yy_syntax_error(10, ' }>') #2 E:wwwSmarty-3.0rc4libssyspluginssmarty_internal_smartytemplatecompiler.php(51): Smarty_Internal_Templateparser->doParse(10, ' }>') #3 E:wwwSmarty-3.0rc4libssysplug in E:wwwSmarty-3.0rc4libssyspluginssmarty_internal_templatecompilerbase.php on line 404

但是网站之前是可以运行的.排除php版本的问题.查看了下模版,发现报错处的标记是这样的.

<{if $var }>

于是心血来潮,把变量后面的空格去掉了,变成$var}>这样了.

结果一运行,ok了.

后来测试发现,在smarty2.6中,上面的写法是没问题的,但是在smarty3rc4中是不可以的.

暂时的解决办法,去掉空格或者降级smarty版本.

另:

在smarty模版中打印当前smarty版本号的方法如下:

<{$smarty.version}>

发表评论

返回顶部