Passing variable from PHP to Smarty

后端 未结 2 859
傲寒
傲寒 2021-01-29 16:52

I had two script, one in .php and one in .tpl I need to pass the variable in php to the tpl. I tried this one, but nothinng works (but somehow

  1. it works for one or
相关标签:
2条回答
  • 2021-01-29 17:09

    You can use this syntax:

    $res = "Hello World!";
    $this->context->smarty->assign('result', $res);
    

    And passing to .tpl file like this:

    {$result}
    

    Hope this helping you.

    0 讨论(0)
  • 2021-01-29 17:33

    Here is the syntax to send data from php to tpl

    $smarty->assign('variable name with which you can access the data in tpl', $php_data_you_want_to_send);
    

    Update:

    $smarty->assign('rate',$usdidr2);// you just need to write rate without $
    

    You can access it in smarty like {$rate} if it is string You can access it in smarty like {$rate|print_r} if it is array

    0 讨论(0)
提交回复
热议问题