首页 文章

Smarty包含动态内容的tpl?

提问于
浏览
0

我有一点聪明的问题,但不知道如何解决这个问题 .

这是我的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 的文件,因为它是我的新系统 .

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

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

希望有人能提供帮助 .

2 回答

  • 0

    你做这样的事情, Smarty_Data 会帮助你

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

    news 数组发送到 assign 函数 .

  • 1

    这将是一个很好的选择 . 您只需添加PHP标记即可包含PHP文件

    包含“news.php”; {/ PHP}

相关问题