how to assign a javascript variable to a smarty variable

后端 未结 2 1370
Happy的楠姐
Happy的楠姐 2020-12-22 09:07

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)
{           


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-22 09:39

    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());
    

    So what you can do is something like:

        $smarty->assign('timestamp',time()); //in your PHP script
    
        //in your JS
        var currentTS = {$timestamp};
    

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

提交回复
热议问题