简体   繁体   English

我如何在smarty变量中使用javascript?

[英]how i can use javascript within a smarty variable?

How I can place a javascript variable within smarty? 如何在smarty中放置javascript变量?

Following doesn't work: 以下操作无效:

{url controller=myController action=detail id= '+obj.id+' forceSecure} {url controller = myController action = detail id = '+ obj.id +' forceSecure}

as smarty is serverside compiled you wont be able to do it like you expect, but you could do sth like 由于smarty是服务器端编译的,因此您将无法像您期望的那样进行操作,但是您可以像

<script>

var url = "{url controller=myController action=detail forceSecure}"+"&id="+obj.id

</script>

i have no experience with smarty but if ´id´ is part of the url, keeping it blank will possibly throw an exception, so you can parse the parameter as url parameter like in my example or you send and parse it as POST parameter 我没有使用smarty的经验,但是如果url中包含“ id”,则将其保留为空白可能会引发异常,因此您可以像在我的示例中一样将参数解析为url参数,或者将其解析为POST参数

Javascript is client side scripting language. Javascript是客户端脚本语言。 You can not use javascript in the server side template engine smarty . 您不能在服务器端模板引擎smarty使用javascript。 This is because the template is going to get evaluated at the server. 这是因为模板将在服务器上进行评估。

You can't assign a client-side value to a smarty variable, as smarty is a templating language that runs on the server. 您不能将客户端值分配给smarty变量,因为smarty是在服务器上运行的模板语言。 Smarty assignments can only be done on the server-side, that is to say, from PHP. Smarty分配只能在服务器端进行,也就是说,可以从PHP进行。

assign smarty 分配聪明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM