[英]Smarty include tpl with dynamic content?
i have a little problem with smarty, but don't know how to fix this. 我对smarty有一点问题,但是不知道如何解决。
This is my index.tpl 这是我的index.tpl
<body>
{include file='header.tpl'}
{include file='leftmenu.tpl'}
<div id=content>
{include file="news.tpl" }
{include file="rightmenu.tpl"}
</body>
My problem there is this line 我的问题是这条线
<div id=content>
{include file="news.tpl" }
news.php
is a file which should display news.tpl
, because it is my newssystem. news.php
是一个应该显示news.tpl
的文件,因为它是我的新闻系统。
In news.php
, i query the mysql database and give the result to news.tpl
. 在
news.php
,我查询mysql数据库并将结果提供给news.tpl
。
But when i write the above line, the news.tpl
don't know where the result comes from. 但是,当我写以上行时,
news.tpl
不知道结果来自何处。
Hope someone could help. 希望有人可以帮忙。
You do something like this, Smarty_Data
will help you 您可以执行以下操作,
Smarty_Data
将为您提供帮助
$data = new Smarty_Data;
$data->assign('foo','bar');
$smarty->display('news.tpl',$data);
Sent your news
array to assign
function. 发送
news
数组以assign
功能。
This will be a good alternative. 这将是一个很好的选择。 You can simply add the PHP tag for including the PHP file
您可以简单地添加PHP标记以包含PHP文件
{php} include "news.php";
{php}包括“ news.php”; {/php}
{/ php}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.