2013-01-16 62 views
0

我有一个聪明的小问题,但不知道如何解决这个问题。Smarty包含tpl动态内容?

这是我在index.tpl

<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,因为这是我newssystem文件。

news.php,我查询MySQL数据库和结果交予news.tpl

但是当我写上面的行中,news.tpl不知道在哪里,结果从何而来。

希望有人能够帮助。

+0

你必须到'news.php'代码移动到'index.php'。或'index.php'其他包括'news.php'并没有定义'模板tenderer'路径有.. – Sahal

回答

1

你做这样的事情,Smarty_Data将帮助您

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

发送您的news数组assign功能。

+0

THX您的回复,认为一个方式,我一直在寻找:) – demonking

0

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

{php} include“news.php”; {/ PHP}

+0

没有,真的,因为我必须在tpl中启用php。 – demonking