Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Smarty-将子页面包括到主页_Php_Smarty - Fatal编程技术网

Php Smarty-将子页面包括到主页

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. 你好。一些随机文本

我有默认的模板文件(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.
你好。一些随机文本。
您应该只显示(“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代码的部分