Smarty包含动态内容的tpl


Smarty include tpl with dynamic content?

我有一个小问题,但不知道如何解决这个问题。

这是我的索引。

<body>
    {include file='header.tpl'}
    {include file='leftmenu.tpl'}
    <div id=content>
    {include file="news.tpl" }
    {include file="rightmenu.tpl"}
</body>

我的问题是这一行

<div id=content>
    {include file="news.tpl" }

news.php是一个应该显示news.tpl的文件,因为它是我的新闻系统。

news.php中,我查询mysql数据库,并把结果给news.tpl

但是当我写上面的行,news.tpl不知道结果来自哪里。

希望有人能帮忙。

你这样做,Smarty_Data将帮助你

$data = new Smarty_Data;
$data->assign('foo','bar');
$smarty->display('news.tpl',$data);

news数组发送给assign函数

这将是一个很好的选择。您可以简单地添加PHP标记来包含PHP文件

{php}包括"news.php";{/php}