简体   繁体   中英

Smarty include tpl with dynamic content?

i have a little problem with smarty, but don't know how to fix this.

This is my 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.

In news.php , i query the mysql database and give the result to news.tpl .

But when i write the above line, the news.tpl don't know where the result comes from.

Hope someone could help.

You do something like this, Smarty_Data will help you

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

Sent your news array to assign function.

This will be a good alternative. You can simply add the PHP tag for including the PHP file

{php} include "news.php"; {/php}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM