Php Smarty-将子页面包括到主页
我有默认的模板文件(main.tpl),我想在Php Smarty-将子页面包括到主页,php,smarty,Php,Smarty,我有默认的模板文件(main.tpl),我想在标记之间包含子页面 因此,当用户单击linknews上的expample时,它将显示News.php($smarty->display(“News.tpl”);)和main.tpl组合 -->main.tpl的第一部分+news.tpl+main.tpl的第二部分 tpl将包含一些文本和php代码,而不包含其他内容。例如 Hello, <php echo $username ?>. Some random text. 你好。一些随机文本
标记之间包含子页面
因此,当用户单击linknews上的expample时,它将显示News.php($smarty->display(“News.tpl”);)和main.tpl组合
-->main.tpl的第一部分+news.tpl+main.tpl的第二部分
tpl将包含一些文本和php代码,而不包含其他内容。例如
Hello, <php echo $username ?>. Some random text.
你好。一些随机文本。
您应该只显示(“main.tpl”),并将news.tpl包含在main.tpl中。如果您的模板包含PHP代码,您根本不需要smarty。只需
包含您的模板文件。在PHP中将模板名称分配给smarty变量:
$smarty->assign('module', 'news');
$smarty->display('main.tpl');
在main.tpl中,仅包含模块模板:
<body>{include file="$module.tpl"}</body>
{include file=“$module.tpl”}
您可以在这里找到有关{include}
smarty函数的更多信息:@Miso我想知道为什么大家都没有注意到News.tpl会包含php代码的部分