如何将javascript变量分配给smarty变量 [英] how to assign a javascript variable to a smarty variable

查看:70
本文介绍了如何将javascript变量分配给smarty变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个关于如何将java脚本变量分配给smarty变量的问题。这是代码片段。

I got a problem regarding how to assign a java script variable to a smarty variable. Here is the code snippet.

function getDateInfo(date, wantsClassName)
{                  
    var as_number = Calendar.dateToInt(date); //This as_number is the variable which should be assigned to smarty variable    
}

怎么能我完成了这个。

任何帮助将不胜感激..

any help will be appreciated..

谢谢你提前 - Fero

Thanks n advance -- Fero

推荐答案

您不能将客户端值分配给smarty变量,因为smarty是在服务器上运行的模板语言。 Smarty分配只能在服务器端完成,也就是说,从PHP完成。例如:

You can't assign a client-side value to a smarty variable, as smarty is a templating language that runs on the server. Smarty assignments can only be done on the server-side, that is to say, from PHP. E.g.:

$smarty->assign('timestamp',time());

所以你可以做的是:

    $smarty->assign('timestamp',time()); //in your PHP script

    //in your JS
    var currentTS = {$timestamp};

参见 http://www.smarty.net/manual/en/api.assign.php

这篇关于如何将javascript变量分配给smarty变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆