【问题标题】:Smarty include tpl with dynamic content?Smarty 包含动态内容的 tpl?
【发布时间】:2013-01-16 06:33:07
【问题描述】:

smarty 有点小问题,不知道怎么解决。

这是我的 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 不知道结果是从哪里来的。

希望有人能提供帮助。

【问题讨论】:

  • 您必须将news.php 代码移动到index.php。或者在index.php 中包含news.php 并且不要在那里定义template tenderer 路径..

标签: php smarty


【解决方案1】:

你这样做,Smarty_Data会帮助你

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

将您的 news 数组发送到 assign 函数。

【讨论】:

    【解决方案2】:

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

    {php} 包括“news.php”; {/php}

    【讨论】:

    • 不,真的,因为我必须在 tpl 中启用 php。
    猜你喜欢
    • 1970-01-01
    • 2012-11-28
    • 2011-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多