JavaScript语法修正中的smarty变量

时间:2011-11-29 09:00:24

标签: php smarty

我试图在JavaScript中使用此变量,但我收到语法错误。

<script type="text/javascript">
{literal} 
$.get("mypage.php", { phone:{/literal} "{$smarty.request.phone}"{literal},
time:{/literal}"{$smarty.request.time}"{literal} } );
{/literal}
</script>

2 个答案:

答案 0 :(得分:1)

尝试:

{literal} 
<script type="text/javascript">

$.get("mypage.php", 
{ phone:"{$smarty.request.phone}"}
);
</script>
{/literal}

答案 1 :(得分:0)

仅仅为了记录,使用Smarty3,您不再需要在JS和CSS代码块中使用{literal}。在Smarty3中,Smarty不会解析用白色空格包围的大括号,所以:

if (a == b) { return c; } // Is not parsed by Smarty3
if (a == b) { return {$c}; } // Only {$c} is parsed
if (a == b) {return c;} // This is parsed because there are no white-spaces near braces.

参考:http://www.smarty.net/v3_overview,“{”和“}”(Javascript)自动擒纵