zl程序教程

您现在的位置是:首页 >  后端

当前栏目

解决css和js的{}与smarty定界符冲突问题的两种方法

JS方法CSS 问题 解决 两种 冲突 smarty
2023-06-13 09:15:05 时间
当输入url地址后网页出现:Fatalerror:Uncaughtexception"SmartyCompilerException"withmessage"SyntaxErrorintemplate"E:\wamp\www\cms\system/templates/index.html"online79"$("#job").load("./system/templates/touch/test.php",{catid:3});"-Unexpected":",expectedoneof:"}","""inE:\wamp\www\cms\system\Smarty\sysplugins\smarty_internal_templatecompilerbase.phponline441这样的问题,通常是css和js的{}与smarty定界符冲突导致的。

解决办法有两个:

1.可以把smarty的定界符设成<{}>
复制代码代码如下:

$tpl->left_delimiter="<{";
$tpl->right_delimiter="}>";

2.对于js的{}与smarty定界符冲突,可以用smarty的literal处理,可以把JS代码包含在{literal}{/literal}之间就可以了。
复制代码代码如下:

<{literal}>
$(
<spanstyle="white-space:pre"></span>function(){alert("培训课程")}
);
<{/literal}>