smarty的php标签中如何写带$符的变量

来源:百度知道 编辑:UC知道 时间:2024/05/28 17:02:54
$arr如果是我从.php中得到的一个数组,我怎么让他在.tpl中显示出来
前题是,要在{php}{/php}中赋给一个变量

{php}
$string=$arr;
{/php}

如果你是默认的smarty设置,可以这样做
PHP代码层
//前面代码省略...
$smarty=new $smarty();
$head="这是我第一个网页";
$body="今天是我第一次使用smarty";
$smarty->assign("head",$head);
$smarty->assign("body",$body);
$smarty->display("test.tpl");

TPL显示层
<html>
<head>
<{$head}> //使用<{$这个是你在smarty->assign中设置的变量}>
</head>
<body>
<{$body}> //使用<{$这个是你在smarty->assign中设置的变量}>
</body>
</html>