我有两个脚本,一个在.php中,另一个在.tpl中 我需要将php中的变量传递给tpl。 我尝试了这个,但是nothinng工作(但不知何故
PHP代码:
<?php
$usdidr2 = "12610.198648";
$usdidr2 = number_format($usdidr,2,',','.');
echo $usdidr2;
session_start();
$regValue = $usdidr2;
$_SESSION['regUSDIDR1'] = $regValue;
?>
SMARTY代码:
<li>
<a href="example.php"><strong>
{php}
session_start();
$regValue = $_SESSION['regUSDIDR1'];
$regValue2 = number_format(45.99*$regValue,2,',','.');
echo "Rp. ".$regValue."";
print_r($regValue);
{/php}
</strong></a>
</li>
答案 0 :(得分:1)
以下是将数据从php发送到tpl
的语法$smarty->assign('variable name with which you can access the data in tpl', $php_data_you_want_to_send);
<强>更新强>
$smarty->assign('rate',$usdidr2);// you just need to write rate without $
如果它是字符串,您可以像{$rate}
那样聪明地访问它
你可以像{$rate|print_r}
那样聪明地访问它,如果它是数组
答案 1 :(得分:0)
您可以使用以下语法:
$res = "Hello World!";
$this->context->smarty->assign('result', $res);
并像这样传递给.tpl文件:
{$result}
希望这对你有所帮助。