【问题标题】:Smarty - include subpages to main pageSmarty - 将子页面包含到主页面
【发布时间】:2011-08-28 14:43:35
【问题描述】:

我有默认模板文件 (main.tpl),我想在 <body> 标签之间包含子页面。

所以当用户点击链接 News 上的示例时,它会显示 news.php ($smarty->display("news.tpl");) 结合 main.tpl

--> main.tpl 的第一部分 + news.tpl + main.tpl 的第二部分。

News.tpl 将包含一些文本和 php 代码,仅此而已。例如。

Hello, <php echo $username ?>. Some random text.

【问题讨论】:

    标签: php smarty


    【解决方案1】:

    在 PHP 中将模板名称分配给 smarty 变量:

    $smarty->assign('module', 'news');
    $smarty->display('main.tpl');
    

    在 main.tpl 中只包含模块模板:

    <body>{include file="$module.tpl"}</body>
    

    您可以在此处找到更多关于{include} smarty 功能的信息:http://www.smarty.net/docs/en/language.function.include.tpl

    【讨论】:

    • @Miso 我想知道为什么你们都没有注意到News.tpl would contain php code 部分
    【解决方案2】:

    您应该只是 $smarty-&gt;display("main.tpl"),并将 news.tpl 包含在您的 main.tpl 中。

    【讨论】:

      【解决方案3】:

      如果您的模板包含 PHP 代码,则根本不需要 Smarty。只需 include 您的模板文件即可。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-06-04
        • 2021-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-08
        相关资源
        最近更新 更多