demonking
demonking

Reputation: 2654

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.

Upvotes: 0

Views: 1256

Answers (2)

Kannan Rajendran
Kannan Rajendran

Reputation: 220

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

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

Upvotes: 0

Sahal
Sahal

Reputation: 4146

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.

Upvotes: 1

Related Questions